답안 #998511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998511 2024-06-14T06:01:13 Z fryingduc Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
135 ms 20840 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 1e6 + 6;
const int base = 31;
const int mod = 1e9 + 9;
string s;
int h[maxn], p[maxn];
int get_hash(int l, int r) {
    return (h[r] - (1ll * h[l - 1] * p[r - l + 1] % mod) + mod) % mod;
}
void solve() {
    cin >> s;
    int n = s.size();
    s = ' ' + s;
    for(int i = 1; i <= n; ++i) {
        h[i] = (1ll * h[i - 1] * base % mod + (s[i] - 'a' + 1)) % mod;
    }
    
    int l = 1, r = n;
    int res = 0;
    for(int i = 1; i <= n / 2; ++i) {
        if(l >= r) break;
        if(get_hash(l, i) == get_hash(r - (i - l), r)) {
            res += 2;
            r = r - (i - l) - 1;
            l = i + 1;
        }
    }
    if(l <= (n + 1) / 2) ++res;
    
    cout << res << '\n';
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    p[0] = 1;
    for(int i = 1; i < maxn; ++i) {
        p[i] = (1ll * p[i - 1] * base) % mod;
    }
    
    int tt; cin >> tt;
    while(tt--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4700 KB Output is correct
2 Correct 5 ms 4700 KB Output is correct
3 Correct 5 ms 4700 KB Output is correct
4 Correct 5 ms 4736 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4700 KB Output is correct
2 Correct 5 ms 4700 KB Output is correct
3 Correct 5 ms 4700 KB Output is correct
4 Correct 5 ms 4736 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 5 ms 4696 KB Output is correct
7 Correct 5 ms 4700 KB Output is correct
8 Correct 5 ms 4696 KB Output is correct
9 Correct 5 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4700 KB Output is correct
2 Correct 5 ms 4700 KB Output is correct
3 Correct 5 ms 4700 KB Output is correct
4 Correct 5 ms 4736 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 5 ms 4696 KB Output is correct
7 Correct 5 ms 4700 KB Output is correct
8 Correct 5 ms 4696 KB Output is correct
9 Correct 5 ms 4700 KB Output is correct
10 Correct 7 ms 4700 KB Output is correct
11 Correct 6 ms 4700 KB Output is correct
12 Correct 6 ms 4700 KB Output is correct
13 Correct 7 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4700 KB Output is correct
2 Correct 5 ms 4700 KB Output is correct
3 Correct 5 ms 4700 KB Output is correct
4 Correct 5 ms 4736 KB Output is correct
5 Correct 5 ms 4700 KB Output is correct
6 Correct 5 ms 4696 KB Output is correct
7 Correct 5 ms 4700 KB Output is correct
8 Correct 5 ms 4696 KB Output is correct
9 Correct 5 ms 4700 KB Output is correct
10 Correct 7 ms 4700 KB Output is correct
11 Correct 6 ms 4700 KB Output is correct
12 Correct 6 ms 4700 KB Output is correct
13 Correct 7 ms 4700 KB Output is correct
14 Correct 135 ms 19852 KB Output is correct
15 Correct 77 ms 15120 KB Output is correct
16 Correct 130 ms 20840 KB Output is correct
17 Correct 74 ms 12904 KB Output is correct