이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2,fma")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
const long long int N = 1e6+20,mod = 1e9+7,inf = 1e9+10,sq = 400;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int n,int k){
int c = 1;
while (k){
if (k&1) c = (1ll*c*n)%mod;
n = (1ll*n*n)%mod;
k >>= 1;
}
return c;
}
int pw[N];
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
int T;
cin >> T;
pw[0] = 1;
rep(i,1,N) pw[i] = 1ll*307*pw[i-1]%mod;
while (T--){
int n;
string s;
cin >> s;
n = s.size();
if (n == 1){
cout << 1 << endl;
continue;
}
int ans = 0,h = 0,g = 0,l = 0, r = n-1;
int t = 0;
while (r > l){
h = mkay((s[l]-'a'+1),1ll*h*307%mod);
g = mkay(g,1ll*(s[r]-'a'+1)*pw[t]%mod);
t++;
r--;
l++;
if (h == g){
ans += 2;
if (l == r) ans++;
t = 0;
h = 0;
g = 0;
continue;
}
if (r <= l){
ans++;
break;
}
}
cout << ans << endl;
}
}
# | 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... |