제출 #1225780

#제출 시각아이디문제언어결과실행 시간메모리
1225780giorgi123glmPalindromic Partitions (CEOI17_palindromic)C++20
0 / 100
0 ms320 KiB
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
using namespace std;

#define int long long

const int mod = 1e9 + 9;

signed main () {
    ios::sync_with_stdio (false);
    cin.tie (0);
    cout.tie (0);

    int t = 0;
    cin >> t;

    while (t--) {
        string str;
        cin >> str;

        int N = str.size();
        str = " " + str;

        int hash1 = 0;
        int hash2 = 0;
        int pow = 1;

        int ans = 0;
        for (int i = 1; i <= (N + 1) / 2; i++) {
            hash1 = (26 * hash1) + (str[i] - 'a');
            hash1 %= mod;

            hash2 += (str[N - i + 1] - 'a') * pow;
            pow *= 26, pow %= mod;
            hash2 %= mod;

            if (hash1 == hash2) {
                ans += (i == (N + 1) / 2 ? 1 : 2);
                hash1 = hash2 = 0;
                pow = 1;
            }
        }

        if (hash1 != 0)
            ans++;

        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...