답안 #972145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972145 2024-04-30T07:26:09 Z efedmrlr Palindromic Partitions (CEOI17_palindromic) C++17
60 / 100
26 ms 8236 KB
#include <bits/stdc++.h>

#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 1e5 + 5;
const lli INF = 1e17;
const int MOD = 1e9 + 7;
const int B = 3;
array<int, B> P = {31, 37, 73};
array<array<int, N>, B> pw;
int add(int x, int y) {
    if(x + y >= MOD) return x + y - MOD;
    return x + y; 
}
int subt(int x, int y) {
    if(x - y < 0) return x - y + MOD;
    return x - y;
}
int mult(int x, int y) {
    return (int)(1ll * x * y % MOD);
}
int fp(int x, int y) {
    int ret = 1;
    while(y > 0) {
        if(y & 1) {
            ret = mult(ret, x);
        }
        x = mult(x, x);
        y >>= 1;
    }
    return ret;
}
int n;
string s;
void solve() {
    cin >> s;
    n = (int)s.size();
    int ans = 0;
    array<int, B> fr, en;
    REP(b, B) {
        fr[b] = en[b] = 0;
    }
    int len = 0;
    int i = 0;
    for(; i < (n - 1) / 2 + 1; i++) {
        int j = n - i - 1;
        REP(b, B) {
            fr[b] = add(mult(fr[b], P[b]), s[i] - 'a' + 1);
            en[b] = add(en[b], mult(s[j] - 'a' + 1, pw[b][len])); 
        }
        len++;
        bool f = 1;
        REP(b, B) {
            if(fr[b] != en[b]) f = 0;
        }
        if(f) {
            ans += 2;
            if(i == j) ans--;
            len = 0;
            REP(b, B) {
                fr[b] = en[b] = 0;
            }
        }
    }
    if(len > 0) ans++;
    cout << ans << "\n";
}

signed main() {
    REP(b, B) {
        pw[b][0] = 1;
        for(int i = 1; i < N; i++) {
            pw[b][i] = mult(pw[b][i - 1], P[b]);
        }
    }
    fastio();
    int test = 1;
    cin >> test;
    while(test--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1628 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1628 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 3 ms 1628 KB Output is correct
11 Correct 3 ms 1624 KB Output is correct
12 Correct 3 ms 1628 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1628 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 3 ms 1628 KB Output is correct
11 Correct 3 ms 1624 KB Output is correct
12 Correct 3 ms 1628 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Runtime error 26 ms 8236 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -