Duplicate topics cannot overlap."Transpose" means that each note in the topic sequence is added or subtracted from the same integer.
For a piece of music, calculate the longest topic length (that is, the number of notes ).
InputThe first line of the output file contains an integer N. Each line below (except the last line may be) contains 20 integers, indicating the sequence of notes. The last line may contain less than 20 notes.
OutputThe output file must contain only one integer, that is, the length of the longest topic. If there is no topic in the music, 0 is output.
Sample Input3025 27 30 34 39 45 52 60 69 69 60 52 45 39 34 30 26 22 1882 78 74 70 66 67 64 60 65 80 Sample Output5HINT
In the example, the topic with a length of 5 is the last five notes in the first line of the input file and the first five notes in the second line.
SourceUSACO
Best Solution
C |
C ++ |
Pascal |
NULL |
80643. wyfcyx (0 ms, 1100KB, 2168B) |
21804. Ares (72 ms, 292KB, 561B) |
[Submit] [Status] [Web Board] Bytes Powered by LLQ .? 2012-2014 Changchun Jilin University attached high school Experimental School.
Question:
Ah, write an array with a suffix, and then divide it into groups based on the height during the binary check, so that each segment can satisfy the height long enough to scan it again, if there is no overlap between the farthest two (sa difference is large enough), return 1...
Code:
#include
#include
#include
#include #define N 21000using namespace std;int s[N];int sa[N],rank[N],h[N],n,m,len;int cnt[N],val[N],stk[N],_val[N],top;bool issame(int a,int b,int hl){return val[a]==val[b]&&((a+hl>=len&&b+hl>=len)||(a+hl
=0;i--)sa[--cnt[val[i]]]=i;for(k=1;;k++){top=0,hl=1<<(k-1);for(i=0;i
=len)stk[top++]=sa[i];for(i=0;i
=hl)stk[top++]=sa[i]-hl;for(i=0;i
=0;i--)sa[--cnt[val[stk[i]]]]=stk[i];for(lim=i=0;i
mid)return 1;}return 0;}int main(){//freopen("test.in","r",stdin);int i,j,k;scanf("%d",&len);scanf("%d",&s[0]);for(i=1;i
>1;if(check(mid))l=mid;else r=mid-1;}if(ans>=4)printf("%d\n",ans+1);else puts("0");return 0;}