이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
string st;
const int N = 1000*1000+5;
long long pw[N];
long long hsh[N];
long long gethash(int l,int r){
return hsh[r]-hsh[l-1]*pw[r-l+1];
}
int solve(int s,int e,int l, int r){
if(l>r) return 0;
if(s == l && e == r && l == r) return 1;
//string s1,s2;
// for(int i = s;i<=l;i++) s1+=st[i];
// for(int i = r;i<=e;i++) s2+=st[i];
long long s1 = gethash(s+1,l+1);
long long s2 = gethash(r+1,e+1);
if(s1 == s2){
return 2+solve(l+1,r-1,l+1,r-1);
}
else{
if(r-l == 1) return 1;
if(r-l == 2) return 1;
return solve(s,e,l+1,r-1);
}
}
int main(){
ios_base::sync_with_stdio(false);
int t;
cin>>t;
pw[0] = 1;
for(int i = 1;i<=1000*1000;i++) pw[i] = pw[i-1]*259;
while(t--){
cin>>st;
for(int i = 1;i<=st.length();i++) hsh[i]=(hsh[i-1]*259+(st[i-1]));
cout<<solve(0,st.length()-1,0,st.length()-1)<<endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
palindromic.cpp: In function 'int main()':
palindromic.cpp:37:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1;i<=st.length();i++) hsh[i]=(hsh[i-1]*259+(st[i-1]));
~^~~~~~~~~~~~~
# | 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... |