# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
707800 | guagua0407 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 316 ms | 28632 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=1e6+5;
ll p=27;
ll mod=(1ll<<61)-1;
ll powv[mxn];
ll hashv[mxn];
void pre(){
powv[0]=1;
for(int i=1;i<mxn;i++){
powv[i]=((__int128)powv[i-1]*p)%mod;
}
}
void genhash(string str){
for(int i=1;i<=str.length();i++){
hashv[i]=((__int128)hashv[i-1]*p%mod+str[i-1]-'a'+1)%mod;
}
}
ll cal(int l,int r){
ll ans=(hashv[r]-(__int128)hashv[l-1]*powv[r-l+1]%mod)%mod;
if(ans<0) ans+=mod;
return ans;
}
void solve(){
string str;
cin>>str;
int n=str.length();
genhash(str);
int l=1;
int ans=0;
while(l<=n/2){
int r=l;
bool tf=false;
while(r<=n/2){
if(cal(l,r)==cal(n-l+1-(r-l+1)+1,n-l+1)){
tf=true;
break;
}
r++;
}
if(tf){
ans++;
l=r+1;
}
else{
break;
}
}
ans*=2;
if(l!=n/2+1 or n&1) ans++;
cout<<ans<<'\n';
}
int main() {_
//setIO("wayne");
pre();
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
//maybe its multiset not set
컴파일 시 표준 에러 (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... |