A953 | Where Am I
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John has gone out for a walk down the road and thinks he may now be
lost!
Along the road there are $N$ farms ($1 \leq N \leq 100$) in a row. Farms
unfortunately do not have house numbers, making it hard for Farmer John to
figure out his location along the road. However, each farm does have a
colorful mailbox along the side of the road, so Farmer John hopes that if he
looks at the colors of the mailboxes nearest to him, he can uniquely determine
where he is.
Each mailbox color is specified by a letter in the range A..Z, so the sequence
of $N$ mailboxes down the road can be represented by a string of length $N$
containing letters in the range A..Z. Some mailboxes may have the same colors
as other mailboxes. Farmer John wants to know what is the smallest value of
$K$ such that if he looks at any sequence of $K$ consecutive mailboxes, he can
uniquely determine the location of that sequence along the road.
For example, suppose the sequence of mailboxes along the road is 'ABCDABC'.
Farmer John cannot set $K=3$, since if he sees 'ABC', there are two possible
locations along the road where this consecutive set of colors might be. The
smallest value of $K$ that works is $K=4$, since if he looks at any
consecutive set of 4 mailboxes, this sequence of colors uniquely determines
his position along the road.
lost!
Along the road there are $N$ farms ($1 \leq N \leq 100$) in a row. Farms
unfortunately do not have house numbers, making it hard for Farmer John to
figure out his location along the road. However, each farm does have a
colorful mailbox along the side of the road, so Farmer John hopes that if he
looks at the colors of the mailboxes nearest to him, he can uniquely determine
where he is.
Each mailbox color is specified by a letter in the range A..Z, so the sequence
of $N$ mailboxes down the road can be represented by a string of length $N$
containing letters in the range A..Z. Some mailboxes may have the same colors
as other mailboxes. Farmer John wants to know what is the smallest value of
$K$ such that if he looks at any sequence of $K$ consecutive mailboxes, he can
uniquely determine the location of that sequence along the road.
For example, suppose the sequence of mailboxes along the road is 'ABCDABC'.
Farmer John cannot set $K=3$, since if he sees 'ABC', there are two possible
locations along the road where this consecutive set of colors might be. The
smallest value of $K$ that works is $K=4$, since if he looks at any
consecutive set of 4 mailboxes, this sequence of colors uniquely determines
his position along the road.
输入格式
The first line of input contains $N$, and the second line contains a string of
$N$ characters, each in the range A..Z.
$N$ characters, each in the range A..Z.
输出格式
Print a line containing a single integer, specifying the smallest value of $K$
that solves Farmer John's problem.
that solves Farmer John's problem.
输入输出样例
输入 #1
7 ABCDABC
输出 #1
4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted