#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
using namespace std;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}
const int N = 1e6 + 15;
const int base = 311;
const int MOD = 998244353;
int add(int a, int b) {if(a >= MOD - b) return a - MOD + b; return a + b;}
int sub(int a, int b) {if(a < b) return a + MOD - b; return a - b;}
int mul(int a, int b) {return 1LL*a*b % MOD;}
int pw[N];
void solve(){
string s; cin >> s;
int n = sz(s);
s = '.' + s;
vector<int> H(n + 15, 0);
for(int i = 1; i <= n; i++) H[i] = add(mul(H[i-1], base), s[i]);
auto get_pref = [&](int l, int r) -> int{
return sub(H[r], mul(H[l-1], pw[r - l + 1]));
};
int l = 1, r = n, st = 1, en = n;
int res = 0;
while(l < r){
if(get_pref(st,l) == get_pref(r,en)){
//cout << st << " " << l << " " << r << " " << en << endl;
res += 2;
st = l+1;
en = r-1;
if(l + 1 == r) break;
}
if(en < st) break;
l++;
r--;
}
res += (l >= r);
cout << res << endl;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
pw[0] = 1;
for(int i = 1; i < N; i++) pw[i] = mul(pw[i-1], base);
int t; t = 1; cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
palindromic.cpp: In function 'int main()':
palindromic.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |