답안 #519339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519339 2022-01-26T08:11:14 Z hoanghq2004 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
176 ms 20752 KB
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e6 + 10;
const int base = 31;
const int mod = 1e9 + 7;

int h[N], power[N];

int get(int L, int R) {
    return (0LL + h[R] - 1LL * h[L - 1] * power[R - L + 1] + 1LL * mod * mod) % mod;
}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 1; i <= n; ++i) h[i] = (1LL * h[i - 1] * base + s[i - 1] - 'a' + 1) % mod;
    power[0] = 1;
    for (int i = 1; i <= n; ++i) power[i] = 1LL * power[i - 1] * base % mod;
    int i = 1, ans = 0;
    while (1) {
        int j = n - i + 1;
        for (int len = 0; len <= n; ++len) {
            if (get(i, i + len) == get(j - len, j)) {
                ans += (i + len != j ? 2 : 1);
                i += len;
                j -= len;
                break;
            }
        }
        ++i, --j;
        if (i > j) break;
    }
    cout << ans << '\n';
}

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    int T;
    cin >> T;
    while (T--) solve();
}

Compilation message

palindromic.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
palindromic.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 176 ms 20752 KB Output is correct
15 Correct 98 ms 15588 KB Output is correct
16 Correct 161 ms 19612 KB Output is correct
17 Correct 94 ms 11032 KB Output is correct