답안 #1066115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1066115 2024-08-19T15:10:06 Z aufan Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
221 ms 27872 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int key = 29;
const int mod = 1e9 + 9;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int t;
        cin >> t;

        while (t --> 0) {
                string s;
                cin >> s;

                int n = (int)s.size();
                vector<int> pr(n + 1);
                for (int i = 0; i < n; i++) {
                        pr[i + 1] = (pr[i] * key + (s[i] - 'a')) % mod;
                }

                vector<int> pw(n + 1);
                pw[0] = 1;
                for (int i = 1; i <= n; i++) pw[i] = (pw[i - 1] * key) % mod;

                auto get = [&](int lf, int rg) {
                        return (pr[rg] - pr[lf - 1] * pw[rg - lf + 1] % mod + mod) % mod;
                };

                int ans = 0;
                for (int i = 1, j = 0; i <= n; i++) {
                        if (get(j + 1, i) == get(n - i + 1, n - j)) {
                                ans += 1;
                                j = i;
                        }
                }

                cout << ans << '\n';
        }
        
        return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 696 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 696 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
14 Correct 216 ms 27872 KB Output is correct
15 Correct 110 ms 22532 KB Output is correct
16 Correct 221 ms 26180 KB Output is correct
17 Correct 114 ms 15216 KB Output is correct