Submission #977670

# Submission time Handle Problem Language Result Execution time Memory
977670 2024-05-08T09:02:45 Z berr Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
85 ms 29584 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+29;
const int mod = 1e9+7;
 
 
int mul(int x, int y){
    x*=y;
    x-=(x/mod)*mod;
    return x;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    int t; cin >> t;
    vector<int> p(1e6+38);
    p[0] = 1;
    for(int i=1; i<=1e6; i++){
        p[i] = mul(p[i-1], 29);
    }
 
 
    while(t--){
        string s; cin >> s;
        int n = s.size();
        int sum=0, ans=0;
        vector<int> va(n);

        for(int i=0; i<n; i++){
            sum+=mul((s[i]-'a'+1),p[i+1]);
            if(sum>=mod) sum-=mod;
            va[i]=sum;
        }
 
        int s2=0, l=0, plast=n;
        int siz=0;
        for(int i=n-1; i>=n/2; i--){
            s2=mul(s2, 29);
            s2+=mul((s[i]-'a'+1), 29);
            if(s2>=mod) s2-=mod;
            int val= (l+ mul(s2, p[n-plast]));
            if(val>=mod) val-=mod;

            if(val==va[n-i-1]){
                ans+=2; 
                siz+=(plast-i)*2;
                if(siz>n) ans--, siz-=(plast-i);
                l=val;
                s2=0;
                plast=i;
            }
        }
 
        if(siz!=n) ans++;
        cout<<ans<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8284 KB Output is correct
2 Correct 9 ms 8284 KB Output is correct
3 Correct 9 ms 8284 KB Output is correct
4 Correct 10 ms 8280 KB Output is correct
5 Correct 9 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8284 KB Output is correct
2 Correct 9 ms 8284 KB Output is correct
3 Correct 9 ms 8284 KB Output is correct
4 Correct 10 ms 8280 KB Output is correct
5 Correct 9 ms 8284 KB Output is correct
6 Correct 9 ms 8284 KB Output is correct
7 Correct 9 ms 8536 KB Output is correct
8 Correct 11 ms 8284 KB Output is correct
9 Correct 10 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8284 KB Output is correct
2 Correct 9 ms 8284 KB Output is correct
3 Correct 9 ms 8284 KB Output is correct
4 Correct 10 ms 8280 KB Output is correct
5 Correct 9 ms 8284 KB Output is correct
6 Correct 9 ms 8284 KB Output is correct
7 Correct 9 ms 8536 KB Output is correct
8 Correct 11 ms 8284 KB Output is correct
9 Correct 10 ms 8284 KB Output is correct
10 Correct 11 ms 8496 KB Output is correct
11 Correct 9 ms 8420 KB Output is correct
12 Correct 11 ms 8284 KB Output is correct
13 Correct 10 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8284 KB Output is correct
2 Correct 9 ms 8284 KB Output is correct
3 Correct 9 ms 8284 KB Output is correct
4 Correct 10 ms 8280 KB Output is correct
5 Correct 9 ms 8284 KB Output is correct
6 Correct 9 ms 8284 KB Output is correct
7 Correct 9 ms 8536 KB Output is correct
8 Correct 11 ms 8284 KB Output is correct
9 Correct 10 ms 8284 KB Output is correct
10 Correct 11 ms 8496 KB Output is correct
11 Correct 9 ms 8420 KB Output is correct
12 Correct 11 ms 8284 KB Output is correct
13 Correct 10 ms 8540 KB Output is correct
14 Correct 85 ms 29584 KB Output is correct
15 Correct 54 ms 23748 KB Output is correct
16 Correct 85 ms 27580 KB Output is correct
17 Correct 48 ms 19168 KB Output is correct