Submission #40120

# Submission time Handle Problem Language Result Execution time Memory
40120 2018-01-27T11:51:16 Z toonewbie Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
1340 ms 13852 KB
#include <bits/stdc++.h>
 
#define intt long long
#define all(v) (v).begin(),v.end()
 
const intt maxx = 1000006;
const intt MOD = 1000000009;
using namespace std;
 
intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    while (b) {
        if (b & 1)
            res *= a;
        res %= mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}
 
intt h[maxx];
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    /*
    string a = "bonobo";
    intt t = 31;
    for (intt i = 0; i < a.size(); i++)
        h[i] = (h[i - 1] + t * (a[i] - 'a')) % MOD, t = (t * 31) % MOD;
    cout << (h[1] * powmod (31, 1, MOD) % MOD) << " " << (h[5] - h[3]) * powmod (31, 5, MOD) % MOD << endl;
    */
    //freopen ("in.txt", "r", stdin);
    /*
    string s = "bonobo";
    intt n = s.size(), t = 31;
    for (intt i = 0; i < n; i++)
        h[i] = (h[i - 1] + t * (s[i] - 'a')) % MOD, t = (t * 31) % MOD;
    for (intt i = 0; i < n; i++)
        cout << h[i] << " ";
    cout << endl;
    return 0;
    */
    intt T;
    cin >> T;
    while (T --) {
        memset (h, 0, sizeof (h));
        string s;
        cin >> s;
        intt n = s.size(), t = 31;
        for (intt i = 0; i < n; i++)
            h[i] = (h[i - 1] + t * (s[i] - 'a')) % MOD, t = (t * 31) % MOD;
        intt ll = 0, lr = n - 1, ans = 0;
        for (intt l = 0, r = n - 1; l < r && 0 < r; l ++, r --) {
            intt h1 = (h[l] - h[ll - 1] + MOD + MOD + MOD) * powmod (31, r, MOD);
            h1 %= MOD;
            intt h2 = (h[lr] - h[r - 1] + MOD + MOD + MOD) * powmod (31, ll, MOD);
            h2 %= MOD;
            if (h1 == h2) {
                //cout << ll << " " << lr << endl;
                ans += 2, ll = l + 1, lr = r - 1;
            }
        }
        cout << ans + 1 - (ll > lr) << endl;
        //break;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9992 KB Output is correct
2 Correct 3 ms 9992 KB Output is correct
3 Correct 8 ms 9992 KB Output is correct
4 Correct 3 ms 9992 KB Output is correct
5 Correct 6 ms 9992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9992 KB Output is correct
2 Correct 3 ms 9992 KB Output is correct
3 Correct 8 ms 9992 KB Output is correct
4 Correct 3 ms 9992 KB Output is correct
5 Correct 6 ms 9992 KB Output is correct
6 Correct 12 ms 9992 KB Output is correct
7 Correct 0 ms 9992 KB Output is correct
8 Correct 4 ms 9992 KB Output is correct
9 Correct 3 ms 9992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9992 KB Output is correct
2 Correct 3 ms 9992 KB Output is correct
3 Correct 8 ms 9992 KB Output is correct
4 Correct 3 ms 9992 KB Output is correct
5 Correct 6 ms 9992 KB Output is correct
6 Correct 12 ms 9992 KB Output is correct
7 Correct 0 ms 9992 KB Output is correct
8 Correct 4 ms 9992 KB Output is correct
9 Correct 3 ms 9992 KB Output is correct
10 Correct 13 ms 9992 KB Output is correct
11 Correct 8 ms 9992 KB Output is correct
12 Correct 15 ms 9992 KB Output is correct
13 Correct 14 ms 9992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9992 KB Output is correct
2 Correct 3 ms 9992 KB Output is correct
3 Correct 8 ms 9992 KB Output is correct
4 Correct 3 ms 9992 KB Output is correct
5 Correct 6 ms 9992 KB Output is correct
6 Correct 12 ms 9992 KB Output is correct
7 Correct 0 ms 9992 KB Output is correct
8 Correct 4 ms 9992 KB Output is correct
9 Correct 3 ms 9992 KB Output is correct
10 Correct 13 ms 9992 KB Output is correct
11 Correct 8 ms 9992 KB Output is correct
12 Correct 15 ms 9992 KB Output is correct
13 Correct 14 ms 9992 KB Output is correct
14 Correct 1307 ms 13764 KB Output is correct
15 Correct 590 ms 13588 KB Output is correct
16 Correct 1340 ms 13852 KB Output is correct
17 Correct 842 ms 12056 KB Output is correct