# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
141315 | rzbt | Palindromic Partitions (CEOI17_palindromic) | C++14 | 165 ms | 26712 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 1000006
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;
char s[MAXN];
ll n;
ll p[MAXN];
ll hes[MAXN];
void hesuj(){
p[0]=1;
hes[1]=s[0]-'a';
for(int i=1;i<n;i++){
p[i]=(p[i-1]*37)%MOD;
hes[i+1]=(hes[i]+p[i]*(s[i]-'a'))%MOD;
}
}
int main()
{
int ttt;
scanf("%d",&ttt);
while(ttt--){
scanf("%s",s);
n=strlen(s);
int l=0,d=n-1,pl=0,pd=n-1,res=0;
hesuj();
while(l<=d){
if(pl==pd)break;
if(((MOD+hes[l+1]-hes[pl])*p[d])%MOD==((MOD-hes[d]+hes[pd+1])*p[pl])%MOD){
res+=2;
pl=l+1;
pd=d-1;
}
l++;
d--;
}
if(pl>pd)printf("%d\n",res);
else{
printf("%d\n",res+1);
}
}
return 0;
}
컴파일 시 표준 에러 (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... |