제출 #128094

#제출 시각아이디문제언어결과실행 시간메모리
128094faustaadpPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
77 ms10640 KiB
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
string s,s1,s2;
ll n,i,has,t;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		has=0;
		cin>>s;
		ll las1=0,las2=n-1;
		n=s.length();
		ll K1=27,P1=1,mo=1e9+7;
		ll A=0,B=0;
		for(i=0;i<n;i++)
		{
			if(i>=(n-i-1))break;
			A=(A*K1)%mo;
			A=(A+(s[i]-'a'))%mo;
			B=(B+((s[n-i-1]-'a')*P1)%mo)%mo;
			P1=(P1*K1)%mo;
			if(A==B)
			{
				las1=i;
				las2=n-i-1;
				las1++;
				las2--;
				has+=2;
				P1=1;
				A=0;
				B=0;
			}
		}
		if(las1<=las2)has++;
		cout<<has<<"\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...