This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 1e5 + 5;
const lli INF = 1e17;
const int MOD = 1e9 + 7;
const int B = 3;
array<int, B> P = {31, 37, 73};
array<array<int, N>, B> pw;
int add(int x, int y) {
if(x + y >= MOD) return x + y - MOD;
return x + y;
}
int subt(int x, int y) {
if(x - y < 0) return x - y + MOD;
return x - y;
}
int mult(int x, int y) {
return (int)(1ll * x * y % MOD);
}
int fp(int x, int y) {
int ret = 1;
while(y > 0) {
if(y & 1) {
ret = mult(ret, x);
}
x = mult(x, x);
y >>= 1;
}
return ret;
}
int n;
string s;
void solve() {
cin >> s;
n = (int)s.size();
int ans = 1;
array<int, B> fr, en;
REP(b, B) {
fr[b] = en[b] = 0;
}
int len = 0;
for(int i = 0; i < n / 2; i++) {
int j = n - i - 1;
if(j == i) break;
REP(b, B) {
fr[b] = add(mult(fr[b], P[b]), s[i] - 'a' + 1);
en[b] = add(en[b], mult(s[j] - 'a' + 1, pw[b][len]));
}
len++;
bool f = 1;
REP(b, B) {
if(fr[b] != en[b]) f = 0;
}
if(f) {
ans += 2;
len = 0;
REP(b, B) {
fr[b] = en[b] = 0;
}
}
}
ans = min(ans, n);
cout << ans << "\n";
}
signed main() {
REP(b, B) {
pw[b][0] = 1;
for(int i = 1; i < N; i++) {
pw[b][i] = mult(pw[b][i - 1], P[b]);
}
}
fastio();
int test = 1;
cin >> test;
while(test--) {
solve();
}
}
# | 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... |