Submission #1338977

#TimeUsernameProblemLanguageResultExecution timeMemory
1338977Born_To_LaughPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
85 ms19536 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 1e9 + 7;

const ll base = 1e8 + 171717;
const int maxn = 1e6 + 10;
ll hashh[maxn];
ll poww[maxn];
int n;
string s;
void cleardata(){}
inline ll get(int l, int r){
    return (hashh[r] - hashh[l - 1] * poww[r - l + 1] % MOD + MOD * MOD) % MOD;
}
void solve(){
    cin >> s;
    n = s.size(); s = "*" + s;
    poww[0] = 1;
    for(int i=1; i<=n; ++i){
        poww[i] = poww[i - 1] * base % MOD;
        hashh[i] = (hashh[i - 1] * base + s[i] - 'a' + 1) % MOD;
    }

    int ans = 1;
    int p1 = 1, p4 = n;
    for(int p2 = 1; p2 <= n / 2; ++p2){
        int p3 = p4 - (p2 - p1);
        if(get(p1, p2) == get(p3, p4)){
            if(n % 2 == 0 && p2 == n / 2) ans--;
            ans += 2;
            p1 = p2 + 1;
            p4 = p3 - 1;
        }
    }
    cout << ans << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;cin >> tt;while(tt--){solve();cleardata();}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...