Submission #915867

# Submission time Handle Problem Language Result Execution time Memory
915867 2024-01-24T20:02:16 Z cper Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
71 ms 17144 KB
# include <bits/stdc++.h>

typedef std::string st;
typedef long long ll;

using namespace std;

ll p[1000006], h[1000006];
ll a, n, l, c, i;
ll h1, h2;

st t;

bool f;

bool check_equal(ll a, ll b, ll l) {
    h1 = (h[a + l - 1] - h[a - 1]) * p[b - a];
    h2 = (h[b + l - 1] - h[b - 1]);

    return h1 == h2;
}

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

    cin >> a;

    while (a --) {
        cin >> t;

        n = t.size();

        p[0] = 1, p[1] = 47;

        for (i = 2; i < n; i ++) {
            p[i] = p[i - 1] * p[1];
        }

        h[0] = 0;

        for (i = 1; i <= n; i ++) {
            h[i] = h[i - 1] + (t[i - 1] - 'a' + 1) * p[i - 1];
        }

        l = 1, c = 0;

        while (l <= n / 2 + (n % 2)) {
            i = 1, f = false;

            for (; i <= n / 2 - l + 1; i ++) {
                // cout << t.substr(l-1, i) << ' ' << t.substr(n - l - i + 1, i) << '\n';

                if (check_equal(l, n - l - i + 2, i)) {
                    // cout << "fuck you\n";
                    c += 2;
                    l = l + i;
                    f = true;
                    break;
                }
            }

            if (!f) {
                // cout << "HEY\n";
                // cout << l << '\n';
                c ++;
                break;
            }
        }

        cout << c << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2548 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2548 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2548 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2548 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2548 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2548 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2548 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 71 ms 17140 KB Output is correct
15 Correct 39 ms 17144 KB Output is correct
16 Correct 66 ms 17144 KB Output is correct
17 Correct 37 ms 11508 KB Output is correct