Submission #47225

# Submission time Handle Problem Language Result Execution time Memory
47225 2018-04-29T10:43:16 Z robert Palindromic Partitions (CEOI17_palindromic) C++14
60 / 100
10000 ms 40556 KB
#include <iostream>
#include <cstring>

using namespace std;

string s;
int N;
int m[1000100];

int solve(int n){
	if(N-n-1<n)
		return 0;
	if(m[n]!=-1)
		return m[n];
	int sol = 1;
	for(int x=N-n-1; x>=n; x--){
		if(s[x]==s[n]){
			//possible beginning of palindromic sequence
			bool m = 1;
			for(int y=0; y+x<=N-n-1; y++){
				if(s[y+x]!=s[n+y])
					m = 0;
			}
			if(m&&x!=n){
				sol = max(sol, 2+solve(N-x));
				break;
			}
		}
	}
	return m[n] = sol;
}

int main(){
	int T; cin>>T;
	while(T--){
		cin>>s;
		N = s.length();
		memset(m, -1, sizeof(m));
		cout << solve(0) << endl;	
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 7 ms 4328 KB Output is correct
3 Correct 5 ms 4428 KB Output is correct
4 Correct 6 ms 4428 KB Output is correct
5 Correct 7 ms 4504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 7 ms 4328 KB Output is correct
3 Correct 5 ms 4428 KB Output is correct
4 Correct 6 ms 4428 KB Output is correct
5 Correct 7 ms 4504 KB Output is correct
6 Correct 6 ms 4592 KB Output is correct
7 Correct 6 ms 4592 KB Output is correct
8 Correct 7 ms 4708 KB Output is correct
9 Correct 7 ms 4708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 7 ms 4328 KB Output is correct
3 Correct 5 ms 4428 KB Output is correct
4 Correct 6 ms 4428 KB Output is correct
5 Correct 7 ms 4504 KB Output is correct
6 Correct 6 ms 4592 KB Output is correct
7 Correct 6 ms 4592 KB Output is correct
8 Correct 7 ms 4708 KB Output is correct
9 Correct 7 ms 4708 KB Output is correct
10 Correct 32 ms 4988 KB Output is correct
11 Correct 36 ms 4988 KB Output is correct
12 Correct 11 ms 4988 KB Output is correct
13 Correct 10 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 7 ms 4328 KB Output is correct
3 Correct 5 ms 4428 KB Output is correct
4 Correct 6 ms 4428 KB Output is correct
5 Correct 7 ms 4504 KB Output is correct
6 Correct 6 ms 4592 KB Output is correct
7 Correct 6 ms 4592 KB Output is correct
8 Correct 7 ms 4708 KB Output is correct
9 Correct 7 ms 4708 KB Output is correct
10 Correct 32 ms 4988 KB Output is correct
11 Correct 36 ms 4988 KB Output is correct
12 Correct 11 ms 4988 KB Output is correct
13 Correct 10 ms 5144 KB Output is correct
14 Execution timed out 10023 ms 40556 KB Time limit exceeded
15 Halted 0 ms 0 KB -