답안 #1011325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011325 2024-06-30T10:34:40 Z Irate Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
152 ms 19804 KB
#include<bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 6;
const int base = 53;
const int MOD = 1e9 + 7;
int H[mxN], P[mxN];
int get_hash(int l, int r){
    return (1LL * H[r] - 1LL * H[l - 1] * P[r - l + 1] % MOD + MOD) % MOD;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    P[0] = 1;
    for(int i = 1;i < mxN;++i){
        P[i] = 1LL * P[i - 1] * base % MOD;
    }
    int t;
    cin >> t;
    while(t--){
        string str;
        cin >> str;
        int n = (int)str.size();
        str = '$' + str;
        for(int i = 1;i <= n;++i){
            H[i] = (1LL * H[i - 1] * base % MOD + (str[i] - 'a' + 1)) % MOD;
        }
        int L = 1;
        int res = 0;
        while(L <= n / 2){
            int p = L;
            while(p <= n / 2 && get_hash(L, p) != get_hash(n - p + 1, n - L + 1)){
                p++;
            }
            if(p > n / 2)break;
            res += 2;
            L = p + 1;
        }
        if(L <= n / 2 + n % 2)res++;
        cout << res << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4188 KB Output is correct
2 Correct 5 ms 4188 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 5 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4188 KB Output is correct
2 Correct 5 ms 4188 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 5 ms 4184 KB Output is correct
6 Correct 6 ms 4188 KB Output is correct
7 Correct 5 ms 4184 KB Output is correct
8 Correct 6 ms 4188 KB Output is correct
9 Correct 6 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4188 KB Output is correct
2 Correct 5 ms 4188 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 5 ms 4184 KB Output is correct
6 Correct 6 ms 4188 KB Output is correct
7 Correct 5 ms 4184 KB Output is correct
8 Correct 6 ms 4188 KB Output is correct
9 Correct 6 ms 4188 KB Output is correct
10 Correct 7 ms 4444 KB Output is correct
11 Correct 7 ms 4196 KB Output is correct
12 Correct 7 ms 4272 KB Output is correct
13 Correct 7 ms 4220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4188 KB Output is correct
2 Correct 5 ms 4188 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 5 ms 4184 KB Output is correct
6 Correct 6 ms 4188 KB Output is correct
7 Correct 5 ms 4184 KB Output is correct
8 Correct 6 ms 4188 KB Output is correct
9 Correct 6 ms 4188 KB Output is correct
10 Correct 7 ms 4444 KB Output is correct
11 Correct 7 ms 4196 KB Output is correct
12 Correct 7 ms 4272 KB Output is correct
13 Correct 7 ms 4220 KB Output is correct
14 Correct 152 ms 19556 KB Output is correct
15 Correct 76 ms 15560 KB Output is correct
16 Correct 126 ms 19804 KB Output is correct
17 Correct 81 ms 12928 KB Output is correct