Submission #205388

# Submission time Handle Problem Language Result Execution time Memory
205388 2020-02-28T18:33:27 Z dolphingarlic Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
50 ms 20784 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef unsigned long long ll;
using namespace std;

const ll P = 29;

ll pw[1000001]{1};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    FOR(i, 1, 1000001) pw[i] = pw[i - 1] * P;

    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        int l = 0, r = s.size() - 1, pl = 0, pr = s.size() - 1;
        int ans = 0;
        ll hsh_l = 0, hsh_r = 0;

        while (l < r) {
            hsh_l = hsh_l * P + (s[l++] - 'a' + 1);
            hsh_r += pw[pr - r] * (s[r--] - 'a' + 1);
            if (hsh_l == hsh_r) {
                FOR(i, 0, l - pl) if (s[pl + i] != s[r + i]) continue;
                ans += 2;
                hsh_l = hsh_r = 0;
                pl = l, pr = r;
            }
        }
        if (l == r || pl != l) ans++;

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

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:26:39: warning: operation on 'r' may be undefined [-Wsequence-point]
             hsh_r += pw[pr - r] * (s[r--] - 'a' + 1);
                                      ~^~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 15 ms 8184 KB Output is correct
3 Correct 14 ms 8184 KB Output is correct
4 Correct 14 ms 8184 KB Output is correct
5 Correct 15 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 15 ms 8184 KB Output is correct
3 Correct 14 ms 8184 KB Output is correct
4 Correct 14 ms 8184 KB Output is correct
5 Correct 15 ms 8184 KB Output is correct
6 Correct 14 ms 8184 KB Output is correct
7 Correct 15 ms 8184 KB Output is correct
8 Correct 14 ms 8184 KB Output is correct
9 Correct 15 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 15 ms 8184 KB Output is correct
3 Correct 14 ms 8184 KB Output is correct
4 Correct 14 ms 8184 KB Output is correct
5 Correct 15 ms 8184 KB Output is correct
6 Correct 14 ms 8184 KB Output is correct
7 Correct 15 ms 8184 KB Output is correct
8 Correct 14 ms 8184 KB Output is correct
9 Correct 15 ms 8184 KB Output is correct
10 Correct 15 ms 8312 KB Output is correct
11 Correct 15 ms 8184 KB Output is correct
12 Correct 14 ms 8328 KB Output is correct
13 Correct 15 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8184 KB Output is correct
2 Correct 15 ms 8184 KB Output is correct
3 Correct 14 ms 8184 KB Output is correct
4 Correct 14 ms 8184 KB Output is correct
5 Correct 15 ms 8184 KB Output is correct
6 Correct 14 ms 8184 KB Output is correct
7 Correct 15 ms 8184 KB Output is correct
8 Correct 14 ms 8184 KB Output is correct
9 Correct 15 ms 8184 KB Output is correct
10 Correct 15 ms 8312 KB Output is correct
11 Correct 15 ms 8184 KB Output is correct
12 Correct 14 ms 8328 KB Output is correct
13 Correct 15 ms 8312 KB Output is correct
14 Correct 50 ms 20784 KB Output is correct
15 Correct 33 ms 15644 KB Output is correct
16 Correct 46 ms 19708 KB Output is correct
17 Correct 39 ms 14756 KB Output is correct