#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
const ll MOD = 1e9 +7;
const ll BASE = 131;
long long modInverse(long long b){
long long ex = MOD - 2;
if (b==1){
return 1;
}
long long r = 1;
while (ex ){
if (ex&1){
r=(r * b)%MOD;
}
ex = ex >> 1;
b = (b * b)%MOD;
}
return r;
}
struct hsh {
vector<ll> pre;
int sz;
ll INV;
vector<ll> inv;
vector<ll> po;
void init(string s){
sz = sz(s);
pre.resize(sz);
inv.resize(sz + 5);
po.resize(sz + 5);
INV = modInverse(BASE);
f0r(i, sz(inv)){
if(i == 0) inv[i] = 1;
else inv[i] = (inv[i-1]*INV)%MOD;
}
f0r(i, sz(po)){
if(i == 0) po[i] = 1;
else po[i] = (po[i-1]*BASE)%MOD;
}
f0r(i, sz){
if(i == 0) pre[i] = (s[i] - 'a')*po[i];
else pre[i] = pre[i-1] + (s[i] - 'a')*po[i];
}
}
ll get(int l, int r){
ll ret = (pre[r] - (l == 0? 0: pre[l-1]))%MOD;
ret *= inv[l];
ret %= MOD;
return ret;
}
};
int solve(string s){
int n = sz(s);
int lo = 0;
int hi = n-1;
int l = lo;
int r = hi;
int ret = 0;
hsh h;
h.init(s);
//bonobo
while(true){
if(l >= r){
ret++;
break;
}
if(h.get(lo, l) == h.get(r, hi)){
ret += 2;
lo = l;
hi = r;
lo++;
hi--;
l = lo;
r = hi;
}
else{
l++;
r--;
}
}
return ret;
}
int main(){
fast_io();
int t;
cin >> t;
string temporary;
getline(cin, temporary);
f0r(i, t){
string s;
getline(cin, s);
cout << solve(s) << endl;
}
return 0;
}
Compilation message
palindromic.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
palindromic.cpp: In function 'void io(std::__cxx11::string)':
palindromic.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
palindromic.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FOUT, "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |