Submission #637713

# Submission time Handle Problem Language Result Execution time Memory
637713 2022-09-02T18:59:38 Z tvladm2009 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
183 ms 20644 KB
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int MAX_N = 1e6;
const int B = 257;
const int P = 1e9 + 7;

int prefH[MAX_N + 1], powerB[MAX_N + 1];

int rangeHash(int l, int r) {
    return (prefH[r] - prefH[l - 1] * 1LL * powerB[r - l + 1] % P + P) % P;
}

void solve(string s) {
    int n = s.size();
    for (int i = 1; i <= n; i++) {
        prefH[i] = (prefH[i - 1] * 1LL * B + (ll)s[i - 1]) % P;
    }
    powerB[0] = 1;
    for (int i = 1; i <= n; i++) {
        powerB[i] = powerB[i - 1] * 1LL * B % P;
    }
    int l = 1, r = n, ans = 0;
    int len = 0;
    while (l < r) {
        len++;
        if (rangeHash(l - len + 1, l) == rangeHash(r, r + len - 1)) {
            ans += 2;
            len = 0;
        }
        l++;
        r--;
    }
    if (len != 0 || l == r) {
        ans++;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        solve(s);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 183 ms 20644 KB Output is correct
15 Correct 106 ms 15552 KB Output is correct
16 Correct 165 ms 19704 KB Output is correct
17 Correct 97 ms 10936 KB Output is correct