# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
850869 | dungz | Palindromic Partitions (CEOI17_palindromic) | C++17 | 92 ms | 20748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll const MOD=1e9+9,base=31;
ll p[1000005];
void sol()
{
string s;
cin>>s;
s=" "+s;
int i=1,j=s.size()-1;
ll hash1=0,hash2=0;
int d=0,ans=0;
p[0]=1;
for(int i=1;i<=s.size()-1;i++)
{
p[i]=(p[i-1]*base)%MOD;
}
int flag=1;
for(int step=1;step<=s.size()/2-(s.size()%2==0?1:0);step++)
{
hash1=(hash1*base+s[i]-'a'+1)%MOD;
hash2=(hash2+(s[j]-'a'+1)*p[d])%MOD;
flag=1;
if(hash1==hash2)
{
flag=0;
hash1=0;
hash2=0;
ans+=2;
d=-1;
}
d++;
i++,j--;
}
if(s.size()%2==1) cout<<ans+flag<<endl;
else cout<<ans+1<<endl;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);
int t;
cin>>t;
while(t--)
{
sol();
}
}
컴파일 시 표준 에러 (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... |