# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1276741 | herominhsteve | Palindromic Partitions (CEOI17_palindromic) | C++20 | 94 ms | 20060 KiB |
#include <bits/stdc++.h>
#define el '\n'
#define FNAME "PARPALIND"
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x) memset(x,0,sizeof(x))
using namespace std;
const long long MOD = (long long) 1e9+7;
void setup(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if (fopen(FNAME".inp","r")) {
freopen(FNAME".inp","r",stdin);
freopen(FNAME".out","w",stdout);
}
}
void timer(){
const int timelimit= 1000;
int runtime= 1000*clock()/CLOCKS_PER_SEC;
if (runtime>timelimit){
cerr<<"TLE: "<<runtime<<el;
}
}
const int base= 257;
const int MAXN= 1e6+1;
long long power[MAXN];
void inHash(string &str, vector<long long> &hashing,int n){
hashing.resize(n+1,0);
for (int i=1;i<=n;i++){
hashing[i]= (hashing[i-1]*base + (str[i-1]-'a'+1))%MOD;
}
}
long long getHash(int l,int r,vector<long long> &hashing){
return (hashing[r]-hashing[l-1]*power[r-l+1]%MOD+ 1ll*MOD*MOD)%MOD;
}
void sol(){
string str;
cin>>str;
int n=str.size();
vector<long long> hashing;
inHash(str,hashing,n);
int res=0;
int l=1;
for (;l<=n/2;l++){
int r= n-l+1;
int i=l;
int j=r;
// [l,i] [j,r]
while (getHash(l,i,hashing)!=getHash(j,r,hashing) and i<=j){
i++;
j--;
}
if (i>j){
break;
}
res+=2;
l=i;
}
if (l<= (n+1)/2) res++;
cout<<res<<el;
}
void queries(){
power[0]=1;
for (int i=1;i<MAXN;i++) power[i]=power[i-1]*base%MOD;
int q;
cin>>q;
while (q--){
sol();
}
}
int main(){
setup();
queries();
timer();
}
컴파일 시 표준 에러 (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... |