Submission #131850

# Submission time Handle Problem Language Result Execution time Memory
131850 2019-07-17T19:47:05 Z Vardanyan Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
90 ms 26872 KB
#include <bits/stdc++.h>
using namespace std;
string st;
const int N = 1000*1000+5;
long long pw[N];
long long hsh[N];
long long gethash(int l,int r){
    return hsh[r]-hsh[l-1]*pw[r-l+1];
}
int solve(int s,int e,int l, int r){
    if(l>r) return 0;
    if(s == l && e == r && l == r) return 1;

    //string s1,s2;
  //  for(int i = s;i<=l;i++) s1+=st[i];
  //  for(int i = r;i<=e;i++) s2+=st[i];
    long long s1 = gethash(s+1,l+1);
    long long s2 = gethash(r+1,e+1);
    if(s1 == s2){

       return 2+solve(l+1,r-1,l+1,r-1);
    }
    else{
        if(r-l == 1) return 1;
        if(r-l == 2) return 1;
        return solve(s,e,l+1,r-1);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    int t;
    cin>>t;
    pw[0] = 1;
    for(int i = 1;i<=1000*1000;i++) pw[i] = pw[i-1]*259;
    while(t--){
        cin>>st;
    for(int i = 1;i<=st.length();i++) hsh[i]=(hsh[i-1]*259+(st[i-1]));
        cout<<solve(0,st.length()-1,0,st.length()-1)<<endl;
    }
    return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:37:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1;i<=st.length();i++) hsh[i]=(hsh[i-1]*259+(st[i-1]));
                   ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8184 KB Output is correct
2 Correct 9 ms 8184 KB Output is correct
3 Correct 18 ms 8184 KB Output is correct
4 Correct 9 ms 8184 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8184 KB Output is correct
2 Correct 9 ms 8184 KB Output is correct
3 Correct 18 ms 8184 KB Output is correct
4 Correct 9 ms 8184 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
6 Correct 9 ms 8184 KB Output is correct
7 Correct 9 ms 8160 KB Output is correct
8 Correct 10 ms 8184 KB Output is correct
9 Correct 9 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8184 KB Output is correct
2 Correct 9 ms 8184 KB Output is correct
3 Correct 18 ms 8184 KB Output is correct
4 Correct 9 ms 8184 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
6 Correct 9 ms 8184 KB Output is correct
7 Correct 9 ms 8160 KB Output is correct
8 Correct 10 ms 8184 KB Output is correct
9 Correct 9 ms 8184 KB Output is correct
10 Correct 10 ms 8312 KB Output is correct
11 Correct 9 ms 8312 KB Output is correct
12 Correct 10 ms 8312 KB Output is correct
13 Correct 10 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8184 KB Output is correct
2 Correct 9 ms 8184 KB Output is correct
3 Correct 18 ms 8184 KB Output is correct
4 Correct 9 ms 8184 KB Output is correct
5 Correct 9 ms 8184 KB Output is correct
6 Correct 9 ms 8184 KB Output is correct
7 Correct 9 ms 8160 KB Output is correct
8 Correct 10 ms 8184 KB Output is correct
9 Correct 9 ms 8184 KB Output is correct
10 Correct 10 ms 8312 KB Output is correct
11 Correct 9 ms 8312 KB Output is correct
12 Correct 10 ms 8312 KB Output is correct
13 Correct 10 ms 8312 KB Output is correct
14 Correct 90 ms 26872 KB Output is correct
15 Correct 55 ms 22236 KB Output is correct
16 Correct 87 ms 26388 KB Output is correct
17 Correct 52 ms 18068 KB Output is correct