Submission #318646

# Submission time Handle Problem Language Result Execution time Memory
318646 2020-11-02T17:13:54 Z Mahdi_Shokoufi Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
206 ms 28568 KB
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())

const int N = 1e6 + 10;
const ll mod = 1000696969;
const ll inf = 1e18 + 10;

ll pw[N], hsh[N];

ll getHash(int l, int r){
    return (hsh[r] - hsh[l - 1] * pw[r - l + 1] % mod + mod) % mod;
}

void solve(){
    string s;
    cin >> s;
    for (int i = 1; i <= sz(s); i ++)
        hsh[i] = (hsh[i - 1] * 27LL % mod + (s[i - 1] - 'a' + 1)) % mod;
    int L = 1, R = sz(s), ans = 0;
    while (L <= R){
        int l = L, r = R, f = 0;
        while (l < r){
            if (getHash(L, l) == getHash(r, R)){
                l ++; r --;
                ans += 2;
                f = 1;
                break;
            }
            l ++; r --;
        }
        L = l; R = r;
        if (f == 0){
            ans ++;
            break;
        }
    }
    cout << ans << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int q;
    cin >> q;
    pw[0] = 1;
    for (int i = 1; i < N; i ++)
        pw[i] = pw[i - 1] * 27LL % mod;
    while (q --)
        solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8172 KB Output is correct
2 Correct 10 ms 8172 KB Output is correct
3 Correct 9 ms 8172 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8172 KB Output is correct
2 Correct 10 ms 8172 KB Output is correct
3 Correct 9 ms 8172 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
6 Correct 10 ms 8172 KB Output is correct
7 Correct 11 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 10 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8172 KB Output is correct
2 Correct 10 ms 8172 KB Output is correct
3 Correct 9 ms 8172 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
6 Correct 10 ms 8172 KB Output is correct
7 Correct 11 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 10 ms 8172 KB Output is correct
10 Correct 12 ms 8428 KB Output is correct
11 Correct 11 ms 8300 KB Output is correct
12 Correct 12 ms 8428 KB Output is correct
13 Correct 11 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8172 KB Output is correct
2 Correct 10 ms 8172 KB Output is correct
3 Correct 9 ms 8172 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
6 Correct 10 ms 8172 KB Output is correct
7 Correct 11 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 10 ms 8172 KB Output is correct
10 Correct 12 ms 8428 KB Output is correct
11 Correct 11 ms 8300 KB Output is correct
12 Correct 12 ms 8428 KB Output is correct
13 Correct 11 ms 8300 KB Output is correct
14 Correct 201 ms 28568 KB Output is correct
15 Correct 115 ms 23520 KB Output is correct
16 Correct 206 ms 27624 KB Output is correct
17 Correct 117 ms 19000 KB Output is correct