Submission #606918

# Submission time Handle Problem Language Result Execution time Memory
606918 2022-07-26T09:53:25 Z pakhomovee Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
143 ms 27572 KB
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#define int long long
const int mod = 1e9 + 9;
const int p = 29;
const int maxn = 1e6 + 10;
int P[maxn];

void hs(vector<int> &h, string &s) {
    for (int i = 1; i <= s.size(); ++i) {
        h[i] = (h[i - 1] * p + (s[i - 1] - 'a' + 1)) % mod;
    }
}

int hsh(int l, int r, vector<int> &h) {
    return ((h[r] - h[l - 1] * P[r - l + 1]) % mod + mod) % mod;
}

void solve() {
    string s;
    cin >> s;
    int i = 0;
    int ans = 0;
    vector<int> h(s.size() + 1, 0);
    hs(h, s);
    while (i <= (s.size() - 1) / 2) {
        int len = 1;
        bool ok = false;
        for (; i + len <= s.size() / 2; ++len) {
            if (hsh(i + 1, i + len, h) == hsh(s.size() - i - len + 1, s.size() - i, h)) {
                ok = true;
                break;
            }
        }
        i += len;
        ans += 1 + ok;
    }
    cout << ans << '\n';
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    P[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        P[i] = (P[i - 1] * p) % mod;
    }
    int t;
    cin >> t;
    while (t--) solve();
}

Compilation message

palindromic.cpp: In function 'void hs(std::vector<long long int>&, std::string&)':
palindromic.cpp:14:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 1; i <= s.size(); ++i) {
      |                     ~~^~~~~~~~~~~
palindromic.cpp: In function 'void solve()':
palindromic.cpp:30:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (i <= (s.size() - 1) / 2) {
      |            ~~^~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:33:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for (; i + len <= s.size() / 2; ++len) {
      |                ~~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8148 KB Output is correct
2 Correct 10 ms 8152 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 9 ms 8148 KB Output is correct
5 Correct 9 ms 8072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8148 KB Output is correct
2 Correct 10 ms 8152 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 9 ms 8148 KB Output is correct
5 Correct 9 ms 8072 KB Output is correct
6 Correct 10 ms 8144 KB Output is correct
7 Correct 10 ms 8148 KB Output is correct
8 Correct 9 ms 8148 KB Output is correct
9 Correct 9 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8148 KB Output is correct
2 Correct 10 ms 8152 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 9 ms 8148 KB Output is correct
5 Correct 9 ms 8072 KB Output is correct
6 Correct 10 ms 8144 KB Output is correct
7 Correct 10 ms 8148 KB Output is correct
8 Correct 9 ms 8148 KB Output is correct
9 Correct 9 ms 8148 KB Output is correct
10 Correct 10 ms 8284 KB Output is correct
11 Correct 9 ms 8276 KB Output is correct
12 Correct 10 ms 8304 KB Output is correct
13 Correct 9 ms 8288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8148 KB Output is correct
2 Correct 10 ms 8152 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 9 ms 8148 KB Output is correct
5 Correct 9 ms 8072 KB Output is correct
6 Correct 10 ms 8144 KB Output is correct
7 Correct 10 ms 8148 KB Output is correct
8 Correct 9 ms 8148 KB Output is correct
9 Correct 9 ms 8148 KB Output is correct
10 Correct 10 ms 8284 KB Output is correct
11 Correct 9 ms 8276 KB Output is correct
12 Correct 10 ms 8304 KB Output is correct
13 Correct 9 ms 8288 KB Output is correct
14 Correct 142 ms 26476 KB Output is correct
15 Correct 89 ms 23540 KB Output is correct
16 Correct 143 ms 27572 KB Output is correct
17 Correct 78 ms 19016 KB Output is correct