Submission #199669

# Submission time Handle Problem Language Result Execution time Memory
199669 2020-02-02T15:55:27 Z algorithm16 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
557 ms 27952 KB
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int llint;
llint h[1000005],p=31337,pot[1000005];
llint get(int a,int b) {
	llint ret=h[b];
	if(a==0) return ret;
	return ret-h[a-1]*pot[b-a+1];
}
int main()
{
	int t;
	cin >> t;
	for(int i=0;i<t;i++) {
		string s;
		cin >> s;
		h[0]=s[0]-'a';
		pot[0]=1;
		pot[1]=p;
		for(int j=1;j<s.size();j++) {
			h[j]=h[j-1]*p+s[j]-'a';
			pot[j+1]=pot[j]*p;
		}
		int x1=0,x2=0,y=s.size()-1,cnt=0;
		while(x2<y) {
			if(get(x1,x2)==get(y-(x2-x1),y)) {
				cnt+=2;
				y-=(x2-x1)+1;
				x1=x2+1;
				x2+=1;
			}
			else x2+=1;
		}
		if(x2<=y) cnt+=1;
		cout << cnt << "\n";
	}
	return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:22:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=1;j<s.size();j++) {
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 11 ms 632 KB Output is correct
11 Correct 8 ms 504 KB Output is correct
12 Correct 10 ms 632 KB Output is correct
13 Correct 10 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 11 ms 632 KB Output is correct
11 Correct 8 ms 504 KB Output is correct
12 Correct 10 ms 632 KB Output is correct
13 Correct 10 ms 508 KB Output is correct
14 Correct 557 ms 27952 KB Output is correct
15 Correct 292 ms 22968 KB Output is correct
16 Correct 513 ms 27092 KB Output is correct
17 Correct 295 ms 15324 KB Output is correct