Submission #1095079

#TimeUsernameProblemLanguageResultExecution timeMemory
1095079vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
100 / 100
36 ms3332 KiB
#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 2e5 + 7, MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);

    int tst;
    cin >> tst;
    while (tst--)
    {
        string s;
        cin >> s;

        int l = 0, r = s.size() - 1, ans = 0;
        ll lt = 0, rt = 0, base = 1;
        while (1)
        {
            lt = (lt * 31 + s[l] - 'a' + 1) % MOD;
            rt = (base * (s[r] - 'a' + 1) + rt) % MOD;
            base = base * 31 % MOD;

            if (lt == rt)
            {
                ans += (l < r) + 1;
                lt = rt = 0;
                base = 1;

                if (l + 1 >= r)
                    break;
            }

            l++;
            r--;
        }

        cout << ans << '\n';
    }
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...