Submission #586300

# Submission time Handle Problem Language Result Execution time Memory
586300 2022-06-30T06:25:56 Z lalala56 Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
170 ms 28800 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7,ba=9907;
const int N=1e6+9;
ll h[N],p[N];
int n,res;
string s;
ll hass(int l,int r){
    return (h[r]-h[l-1]*p[r-l+1]+mod*mod)%mod;
}
void giai(){
    cin>>s;
    n=s.length();
    s=' '+s;
    p[0]=1;
    for(int i=1;i<=n;i++)p[i]=(p[i-1]*ba)%mod;
    for(int i=1;i<=n;i++){
        h[i]=(h[i-1]*ba+int(s[i])-'a'+1)%mod;
    }
    res=0;
    int p=1,q=n;
    //cout<<n<<" "<<s<<" ";
    for(int i=1;i<=n/2;i++){
        if(hass(p,i)==hass(n-i+1,q)){
            //cout<<i<<endl;
            p=i+1;
            q=n-i;
            res+=2;
        }
    }
    if(p<=q)++res;
    cout<<res<<'\n';
}
int main(){
   // freopen("solve.inp","r",stdin);
    //freopen("solve.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)giai();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 2 ms 628 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 2 ms 628 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 170 ms 27628 KB Output is correct
15 Correct 96 ms 22868 KB Output is correct
16 Correct 167 ms 28800 KB Output is correct
17 Correct 90 ms 14656 KB Output is correct