Hotaru ' s problem

Source: Internet
Author: User
Tags cas

Hotaru ' s problem

Time limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 3314 Accepted Submission (s): 1101


Problem Descriptionhotaru Ichijou recently is addicated to math problems. Now she's playing with N-sequence.
Let's define N-sequence, which is composed with three parts and satisfied with the following condition:
1. The first part of the same as the thrid part,
2. The first part and the second part is symmetrical.
For example, the sequence 2,3,4,4,3,2,2,3,4 are a n-sequence, which the first part 2,3,4 are the same as the Thrid Part 2, 3, 4, the first part 2,3,4 and the second part 4,3,2 is symmetrical.

Give you n positive intergers, your task was to find the largest continuous sub-sequence, which is n-sequence.

Inputthere is multiple test cases. The first line of input contains an integer T (t<=20), indicating the number of test cases.

For each test case:

The first line of input contains a positive integer N (1<=n<=100000), the length of a given sequence

The second line includes N non-negative integers, each interger is no larger than9 , descripting a sequence.

Outputeach case contains only one line. Should start with ' case #i: ', with I implying the case number, followed by a integer, the largest length of n-se Quence.

We guarantee the sum of all answers are less than 800000.

Sample Input1102 3 4 4 3 2 2 3 4 4

Sample outputcase #1:9

Authoruestc

Source2015 multi-university Training Contest 7
//On the basis of Manachar, enumerate the center of Palindrome String, then find the third part. #include <cstdio>#include<cstring>#include<iostream>using namespacestd;intRead () {registerintx=0;BOOLf=1; RegisterCharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=0; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnf?x:-x;}Const intn=3e5+Ten;intN,ans,cas,l,t,s[n],s[n],p[n];voidManacher () {intId=0, mx=-1;  for(intI=1; i<l;i++){        if(id+mx>i) P[i]=min (p[id*2-i],id+mx-i);  while(i-p[i]>=0&&i+p[i]<=l&&s[i-p[i]]==s[i+p[i]]) p[i]++; if(Id+mx<i+p[i]) id=i,mx=P[i]; }}voidinit () {L=0; memset (P,0,sizeofp);  for(intI=0; i<n;i++) s[++l]=-1, s[++l]=S[i]; s[++l]=-1; }intMain () { for(T=read (), cas=1; ans=0, cas<=t;cas++) {n=read ();  for(intI=0; i<n;i++) s[i]=read ();        Init (); Manacher ();  for(intI=1; i<=n*2+1; i+=2){             for(intj=i+p[i]-1; j-i>ans;j-=2){                if(j-i+1<=P[j]) {ans=max (ans,j-i);  Break; }}} printf ("Case #%d:%d\n", cas,ans/2*3); }    return 0;}

Hotaru ' s problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.