Submission #586292

# Submission time Handle Problem Language Result Execution time Memory
586292 2022-06-30T06:19:24 Z lalala56 Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
0 ms 340 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=1;
    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;
        }
    }
    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 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -