BOJ 262 Channel Coding

Description
Assume an integer sequence contains N elements whose value could only be one of {0, 1, -1}. There may exist a positive integer D which can make the sum between i-th element and (i+D)-th element be zero, where i is a certain integer between 1 and N-D. Your task is to find out the maximal D.

Input
First line contains a integer T indicate the number of cases. (T<=50)
In each test case, the first line is N descript above. (N<=50000)
Then follows N integers the sequence contains.


Output
Each case output one integer D in a line. If there is no such a D, just output -1.

Sample Input

2
3
1 0 -1
1
1


Sample Output

2
-1

很简单的hash


 

posted on 2012-02-18 17:32  c语言源码  阅读(175)  评论(0编辑  收藏  举报

导航