답안 #942161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942161 2024-03-10T10:22:36 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
60 / 100
111 ms 26728 KB
#include <bits/stdc++.h>
#define endl "\n"
#define int long long

using namespace std;

int q, n, P = 47, cnt = 1;
const int N = 1000000, M = 1000000007;
int p[N], h[N];
string s;

bool check_equal(int a, int b, int l) {
  int ha = (h[a + l] - h[a] + M) % M;
  int hb = (h[b + l] - h[b] + M) % M;
  return 1LL * ha * p[b - a] % M == hb;
}


signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> q;
    p[0] = 1;
    for (int i = 1; i < N; i++)
    {
        p[i] = p[i - 1] * P % M;
    }
    while(q--)
    {
        cin >> s;
        cnt = 1;
        n = s.size();
        h[0] = 0;
        for (int i = 1; i <= n; i++)
        {
            h[i] = (h[i-1] + (1LL * (s[i-1] - 'a' + 1) * p[i - 1] % M)) % M;
        }
        int l = 0, r = n, k = 1;
        while(l < r && l + k <= r - k)
        {
            if(check_equal(l, r - k, k))
            {
                cnt++;
                if (l + k != r-k)cnt++;
                l += k;
                r -= k;
                k = 1;
            }
            else k++;
        }
        cout << cnt << endl;
        memset(h, 0, sizeof(h));

    }
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15964 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Correct 8 ms 16100 KB Output is correct
4 Correct 9 ms 15960 KB Output is correct
5 Correct 8 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15964 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Correct 8 ms 16100 KB Output is correct
4 Correct 9 ms 15960 KB Output is correct
5 Correct 8 ms 15964 KB Output is correct
6 Correct 9 ms 16112 KB Output is correct
7 Correct 8 ms 15964 KB Output is correct
8 Correct 8 ms 15960 KB Output is correct
9 Correct 8 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15964 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Correct 8 ms 16100 KB Output is correct
4 Correct 9 ms 15960 KB Output is correct
5 Correct 8 ms 15964 KB Output is correct
6 Correct 9 ms 16112 KB Output is correct
7 Correct 8 ms 15964 KB Output is correct
8 Correct 8 ms 15960 KB Output is correct
9 Correct 8 ms 15964 KB Output is correct
10 Correct 9 ms 16220 KB Output is correct
11 Correct 8 ms 15960 KB Output is correct
12 Correct 9 ms 16220 KB Output is correct
13 Correct 9 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15964 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Correct 8 ms 16100 KB Output is correct
4 Correct 9 ms 15960 KB Output is correct
5 Correct 8 ms 15964 KB Output is correct
6 Correct 9 ms 16112 KB Output is correct
7 Correct 8 ms 15964 KB Output is correct
8 Correct 8 ms 15960 KB Output is correct
9 Correct 8 ms 15964 KB Output is correct
10 Correct 9 ms 16220 KB Output is correct
11 Correct 8 ms 15960 KB Output is correct
12 Correct 9 ms 16220 KB Output is correct
13 Correct 9 ms 15964 KB Output is correct
14 Incorrect 111 ms 26728 KB Output isn't correct
15 Halted 0 ms 0 KB -