이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9+9, hash_val = 31, N = 1e6;
int hashn[N],pow31[N];
int power(int a, int b){
int ans = 1;
while (b){
if (b&1) ans = (ans*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return ans;
}
int inv(int a){
return power(a,mod-2);
}
int calc(int l, int r){
if (l > r) return 0;
int ans = hashn[r];
if (l != 0) ans -= hashn[l-1];
return (((ans+mod)%mod)*inv(pow31[l]))%mod;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
pow31[0] = 1;
for (int i=1; i<1e6; ++i){
pow31[i] = (pow31[i-1]*hash_val)%mod;
}
int t;
cin >> t;
while (t--){
string s;
cin >> s;
int ans = 0, res = 1, n = s.size(), l = 0, r = n-1;
hashn[0] = s[0]-'a'+1;
for (int i=1; i<n; ++i){
hashn[i] = hashn[i-1]+pow31[i]*(s[i]-'a'+1);
hashn[i] %= mod;
}
while (l < r){
int L = l, R = r;
while ((calc(L,l-1) != calc(r+1,R) or l == L) and l < r){
l++; r--;
}
if (calc(L,l-1) != calc(r+1,R)) break;
ans += 2;
if (l <= r) res = max(res,ans+1);
else res = max(res,ans);
}
cout << res << '\n';
}
return 0;
}
# | 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... |