#PU964. USACO 2019 December Contest, Bronze — Problem 2. Where Am I?

    ID: 1268 传统题 文件IO:whereami 2000ms 256MiB 尝试: 0 已通过: 0 难度: 普及 上传者: 标签>USACO赛事:dec19来源:usaco.orgscoring:equal_test_cases字符串哈希

USACO 2019 December Contest, Bronze — Problem 2. Where Am I?

USACO 2019 December Contest, Bronze — Problem 2. Where Am I?

题目描述

Farmer John has gone out for a walk down the road and thinks he may now be lost! Along the road there are NN farms (1≤N≤1001 \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 NN mailboxes down the road can be represented by a string of length NN 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 KK such that if he looks at any sequence of KK 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=3K=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 KK that works is K=4K=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 NN, and the second line contains a string of NN characters, each in the range A..Z.

输出格式

Print a line containing a single integer, specifying the smallest value of KK that solves Farmer John's problem.

数据范围

(见题面原文)

样例

样例 1

7
ABCDABC
4
Problem credits: Brian Dean