Submission #339426

# Submission time Handle Problem Language Result Execution time Memory
339426 2020-12-25T08:18:23 Z nandonathaniel Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1000005,MOD=1e9+7;
 
int pref[MAXN],pkt[MAXN];
string s;
 
int get(int L,int R){
	if(L>R)return 0;
	return (pref[R]-((1LL*pref[L-1]*pkt[R-L+1])%MOD)+MOD)%MOD;
}

int solve(int L,int R){
	if(L>R)return 0;
	int pjg=R-L+1;
	for(int i=pjg/2;i>=1;i--){
		if(get(L,L+i-1)==get(R-i+1,R))return 2+solve(L+i,R-i);
	}
	return 1;
}
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t,n;
	cin >> t;
	while(t--){
		cin >> s;
		n=(int)s.length();
		pkt[0]=1;
		for(int i=0;i<n;i++){
			pref[i+1]=(26LL*pref[i]+s[i]-'a')%MOD;
			pkt[i+1]=(26LL*pkt[i])%MOD;
		}
		cout << solve(1,n) << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -