# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
939302 | Baytoro | Palindromic Partitions (CEOI17_palindromic) | C++17 | 269 ms | 18996 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fr first
#define sc second
const long long INF=1e17,N=1e6+6,mod=1e9+7;
int p=31;
int h[N],hsh[N];
int hesh(int l, int r){
return (((hsh[r]-hsh[l-1]+mod)%mod)*h[N-r])%mod;
}
deque<int> c[29];
void solve(){
string s;cin>>s;int n=s.size();
h[0]=1;
for(int i=1;i<N;i++){
h[i]=(h[i-1]*p)%mod;
}
for(int i=1;i<=(int)s.size();i++){
hsh[i]=(hsh[i-1]+((s[i-1]-'a'+1)*h[i-1])%mod)%mod;
}
int ans=0;
for(int i=0;i<(n)/2;i++){
int j=i;
int l=n-i-1;
bool ok=0;
for(;j<(n)/2;j++,l--){
//cout<<i<<' '<<j<<':'<<l<<' '<<n-i-1<<endl;
//cout<<hesh(i+1,j+1)<<' '<<hesh(l+1,n-i)<<endl;
//
if(hesh(i+1,j+1)==(hesh(l+1,n-i))){
ok=1;
ans+=2;
if(n%2==0 && j==n/2-1) ans--;
break;
}
//if(j==n/2) ans++;
}
//if(!ok) ans++;
i=j;
}
cout<<ans+1<<endl;
}
main(){
int T=1;
cin>>T;
while(T--){
solve();
}
}
/*
11
7958 4722 9704 6995 1052 5269 7479 8238 6423 7918 866
7659 2498 8486 1196 7462 6633 2158 2022 1146 8392 3037
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |