Submission #1185711

#TimeUsernameProblemLanguageResultExecution timeMemory
1185711mertbbmPalindromic Partitions (CEOI17_palindromic)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<int,pii>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

int mod=1e16+rng()%1000000;

int f(int a, int b){
	if(a==1||b==0) return 1;
	if(b==1) return a;
	int hold=f((a*a)%mod,b/2);
	if(b%2) hold=(hold*a)%mod;
	return hold;
}

void solve(){
	int n;
	cin >> n;
	for(int x=0;x<n;x++){
		string s;
		cin >> s;
		int l=0;
		int r=s.length()-1;
		int counter=0;
		int counter2=0;
		int ans=0;
		int len=0;
		while(l<r){
			int hold=s[l]-'a';
			int hold2=s[r]-'a';
			counter=(counter*29+hold)%mod;
			counter2=(counter2+f(29,len)*hold2)%mod;
			//show2(l,l,r,r);
			//show2(counter,counter,counter2,counter2);
			l++;
			r--;
			len++;
			if(counter==counter2){
				ans+=2;
				len=0;
				counter=0;
				counter2=0;
			}
			if(l==r||(l>r&&len)) ans++;
		}
		cout << ans << "\n";
	}
}	
																   
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...