답안 #226682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226682 2020-04-24T18:52:22 Z keta_tsimakuridze Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
634 ms 18092 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){
				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 Correct 19 ms 16000 KB Output is correct
2 Correct 19 ms 16000 KB Output is correct
3 Correct 20 ms 16000 KB Output is correct
4 Correct 20 ms 16000 KB Output is correct
5 Correct 20 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16000 KB Output is correct
2 Correct 19 ms 16000 KB Output is correct
3 Correct 20 ms 16000 KB Output is correct
4 Correct 20 ms 16000 KB Output is correct
5 Correct 20 ms 16000 KB Output is correct
6 Correct 20 ms 16000 KB Output is correct
7 Correct 20 ms 16000 KB Output is correct
8 Correct 20 ms 16128 KB Output is correct
9 Correct 19 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16000 KB Output is correct
2 Correct 19 ms 16000 KB Output is correct
3 Correct 20 ms 16000 KB Output is correct
4 Correct 20 ms 16000 KB Output is correct
5 Correct 20 ms 16000 KB Output is correct
6 Correct 20 ms 16000 KB Output is correct
7 Correct 20 ms 16000 KB Output is correct
8 Correct 20 ms 16128 KB Output is correct
9 Correct 19 ms 16000 KB Output is correct
10 Correct 26 ms 16000 KB Output is correct
11 Correct 23 ms 16000 KB Output is correct
12 Correct 25 ms 16000 KB Output is correct
13 Correct 25 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16000 KB Output is correct
2 Correct 19 ms 16000 KB Output is correct
3 Correct 20 ms 16000 KB Output is correct
4 Correct 20 ms 16000 KB Output is correct
5 Correct 20 ms 16000 KB Output is correct
6 Correct 20 ms 16000 KB Output is correct
7 Correct 20 ms 16000 KB Output is correct
8 Correct 20 ms 16128 KB Output is correct
9 Correct 19 ms 16000 KB Output is correct
10 Correct 26 ms 16000 KB Output is correct
11 Correct 23 ms 16000 KB Output is correct
12 Correct 25 ms 16000 KB Output is correct
13 Correct 25 ms 16000 KB Output is correct
14 Correct 634 ms 18092 KB Output is correct
15 Correct 347 ms 18020 KB Output is correct
16 Correct 603 ms 18092 KB Output is correct
17 Correct 340 ms 17044 KB Output is correct