답안 #226683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226683 2020-04-24T18:52:48 Z keta_tsimakuridze Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
20 ms 16000 KB
#include<bits/stdc++.h>
using namespace std;
long long mod,p,t,k,i,pwr[1000005],pwr1[1000005],p1,mod1,c1,c2,j,s1,s2,cur,ans;
string s;
int main(){
	cin>>t;
	p=31;
	mod=1e9+7;
	p1=29;
	mod1=1e9+207;
	pwr[1]=1;
	for(k=2;k<=1000005;k++){
		pwr[k]=pwr[k-1]*p%mod;
		pwr1[k]=pwr1[k-1]*p1%mod1;
	}
	while(t--){
		cin>>s;
		j=s.size()-1;
        cur=1;
		for(i=0;i<(s.size())/2;i++){
			s1+=pwr[cur]*((int)s[i]-'a'+1);
			s1%=mod;
			c1+=pwr1[cur]*((int)s[i]-'a'+1);
			c1%=mod1;
			s2=s2*p%mod+((int)s[j]-'a'+1);
			c2=c2*p1%mod1+((int)s[j]-'a'+1);
			c2%=mod1;
			s2%=mod;  
			if(s1==s2 && c1==c2){
				cur=1; s1=s2=c1=c2=0; 
				ans+=2; 
			}else cur++;
			j--;
		} s1=s2=c1=c2=0;
		if(cur!=1 || s.size()%2==1) cout<<ans+1<<endl;
		else cout<<ans<<endl;
		ans=0;
	}
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:20:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=0;i<(s.size())/2;i++){
           ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -