# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
939169 | vjudge1 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 6 ms | 8028 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e6+5,mod=1e9+7,tt=13;
int pw[N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int t;
cin>>t;
pw[0]=1;
for(int i=1;i<N;i++){
pw[i]=pw[i-1]*tt;
pw[i]%=mod;
}
while(t--){
string s;
cin>>s;
s=" "+s;
vector <int> h(s.size());
for(int i=1;i<s.size();i++){
h[i]=h[i-1]*tt+(s[i]-'a'+1);
h[i]%=mod;
}
int st1=1,end2=s.size()-1;
int end1=1,st2=s.size()-1;
int h1=0,h2=0;
int ans=0;
while(end1<st2){
h1=(h[end1]-h[st1-1]*pw[end1-st1+1])%mod;
h2=(h[end2]-h[st2-1]*pw[end2-st2+1])%mod;
if(h1==h2){
end1++;
st1=end1;
st2--;
end2=st2;
ans+=2;
}
else{
st2--;
end1++;
}
}
if(st1<=end2)ans++;
cout<<ans<<"\n";
}
}
/*
*/
컴파일 시 표준 에러 (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... |