답안 #637714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637714 2022-09-02T19:00:08 Z tvladm2009 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
183 ms 10984 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 183 ms 10984 KB Output is correct
15 Correct 102 ms 10608 KB Output is correct
16 Correct 163 ms 10928 KB Output is correct
17 Correct 95 ms 5944 KB Output is correct