제출 #916584

#제출 시각아이디문제언어결과실행 시간메모리
916584vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
100 / 100
151 ms11108 KiB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=(ll)1e17-3;
int t,n;
char s[1000010];
int main() {
	cin>>t;
	int i,j;
	while(t--) {
		cin>>s;
		n=strlen(s);
		j=n;
		ll hl=0,hr=0,pw=1,cnt=0;
		for(i=0;i<n/2;i++) {
			hl=(26*hl+s[i]-'a')%mod;
			hr=(hr+(s[n-i-1]-'a')*pw%mod)%mod;
			if(hl==hr) {
				cnt+=2;
				j=i;
				hl=hr=0; pw=1;
			} else pw=26*pw%mod;
		}
		if(n%2||j!=n/2-1) cnt++;
		cout<<cnt<<endl;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...