Submission #116249

# Submission time Handle Problem Language Result Execution time Memory
116249 2019-06-11T14:28:47 Z Meloric Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
9 ms 4596 KB
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>

using namespace std;
int mod = 1e9+7;
vector<int> mem;
/*
bool same(int l, int r, int len, vector<int>&wrd){
    for(int i = 0; i<=len; i++){
        if(wrd[l+i] != wrd[r+i-len])return false;
    }
    return true;
}*/
int dp(int l, int r, vector<int>&wrd){
    if(r<l)return 0;
    int hsh1, hsh2;hsh1 = 0; hsh2=0;
    for(int i = 0; i+l < r-i ;i++){
        hsh1*=26; hsh1+= wrd[l+i];
        hsh2+= wrd[r-i]*mem[i];
        hsh1%=mod; hsh2%=mod;
        if(hsh1 == hsh2)return dp(l+i+1, r-i-1, wrd)+2;
    }
    return 1;
}
void solve(){
    string in; vector<int> wrd;
    cin >> in;
    for(auto i : in)wrd.pb(i-'a');
    //for(int i : wrd)cout << i <<' ';
    cout << dp(0, wrd.size()-1, wrd)<< '\n';
}
void prec(){
    int pw = 1;
    for(int i = 0; i< 1e6; i++){
        mem.pb(pw);
        pw*=26;
        if(pw>mod)pw-=mod;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t; cin >> t;
    prec();
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 4596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 4596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 4596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 4596 KB Output isn't correct
2 Halted 0 ms 0 KB -