HDU 5371 (Hotaru ' s problem-2 times palindrome string)

Source: Internet
Author: User

Hotaru ' s problemTime limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 2432 Accepted Submission (s): 841


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 than ten 9 , 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 Input
1102 3 4 4 3 2 2 3 4 4

Sample Output
Case #1:9

Authoruestc
Source2015 multi-university Training Contest 7
Recommendwange2014 | We have carefully selected several similar problems for you:5421 5420 5419 5418 5417

Match first, then violence find the second one,

Look for optimizations that are faster than the current answer.





#include <bits/stdc++.h> using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (i,k,n) for (int i=k;i<=n;i++) #define REP (I,n) for (int. i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (i,n) for (int i =n;i>=0;i--) #define FORP (x) for (int p=pre[x];p, p=next[p]) #define FORPITER (x) for (int &p=iter[x];p; p=next[p]) # Define Lson (x<<1) #define Rson ((x<<1) +1) #define MEM (a) memset (A,0,sizeof (a)), #define MEMI (a) memset (a,127 , sizeof (a)), #define MEMI (a) memset (A,128,sizeof (a)), #define INF (2139062143) #define F (100000007) #define MAXN (300000+ Ten) #define SP_CHAR1 ( -1) #define SP_CHAR2 ( -2) typedef long Long Ll;ll Mul (ll A,ll b) {return (a*b)%F;} ll Add (ll A,ll b) {return (a+b)%F;} ll Sub (ll A,ll b) {return (A-b+llabs (a)/f*f+f)%F; void Upd (ll &a,ll b) {a= (a%f+b%f)%F;} int A[maxn],n,r[maxn];class manacher{public:int n;int s[maxn];int p[2*maxn+2];void mem () {n=0; MEM (s) mem (p)}int str[maxn*2+2];void work () {str[0]=sp_char1; Rep (i,n) str[2*i+1]=sp_char2,Str[2*i+2]=s[i]; STR[2*N+1]=SP_CHAR2; str[2*n+2]=-3;n=2*n+2; MEM (p) int mx=0,id=0; for (i,n-1) {if (I&LT;MX) p[i]=min (P[2*id-i],mx-i), while (Str[i-p[i]]==str[i+p[i]]) ++p[i];if (Mx<i+p[i])// MX is the most right end of the identified {Mx=i+p[i];id=i;}}} S;int Main () {//freopen ("c.in", "R", stdin); int t;cin>>t; for (kcase,t) {s.mem (); scanf ("%d", &n); for (I,n) scanf ("%d", &a[i]), s.s[i-1]=a[i]; S.n=n; S.work (); int ans=0;for (int i=3;i<s.n;i+=2) {for (int j=s.p[i];j>ans;j-=2) {if (s.p[i+ (j-1)]>=j) Ans=max (ans,j  ); }}ans= (ans-1)/2*3;printf ("Case #%d:%d\n", Kcase,ans);} return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5371 (Hotaru ' s problem-2 times palindrome string)

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.