답안 #662810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
662810 2022-11-26T12:34:15 Z Kahou Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
553 ms 15052 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1e6 + 50;
const int mod = 1e9 + 7;
const int B = 1742;
int n, h[N];
string s;

int add(int a, int b) {
        a += b;
        if (a >= mod) a -= mod;
        if (a < 0) a += mod;
        return a;
}
int mul(int a, int b) {
        return 1ll*a*b%mod;
}
int pw(int a, int b) {
        int out = 1;
        while (b) {
                if(b&1) out = mul(out, a);
                a = mul(a,a);
                b>>=1;
        }
        return out;
}
int H(int l, int r) {
        return add(h[r], -mul(h[l], pw(B, r-l)));
}

void solve() {
        cin >> s;
        n = s.size();
        for (int i = 1; i <= n; i++) {
                h[i] = add(mul(h[i-1], B), s[i-1]);
        }
        int l = 0;
        int ans = 0;
        for (int r = 1; r <= n-l; r++) {
                if (H(l, r) == H(n-r, n-l)) {
                        ans += 2-(r == n-l);
                        l = r;
                }
        }
        cout << ans << endl;
}
int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        int tc;
        cin >> tc;
        while(tc--) 
                solve();
        return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 496 ms 15052 KB Output is correct
15 Correct 503 ms 10440 KB Output is correct
16 Correct 553 ms 14548 KB Output is correct
17 Correct 95 ms 8128 KB Output is correct