Submission #125323

# Submission time Handle Problem Language Result Execution time Memory
125323 2019-07-05T05:44:29 Z semiauto Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
628 ms 11228 KB
#include <bits/stdc++.h>
using namespace std;
const long long p1=997,r1=1000000007,p2=1439,r2=1000000009;
long long t,ans;
string s;
void solve(long long l,long long r) {
    long long h1=0,h2=0,h3=0,h4=0,s1=1,s2=1;
    while (h1!=h2 || h3!=h4 || !h1) {
        if (l>=r) {
            ans++;
            return;
        }
        s1=(s1*p1)%r1;
        s2=(s2*p2)%r2;
        h1=(h1+s1*(s[l]-'a'+1))%r1;
        h3=(h3+s2*(s[l]-'a'+1))%r2;
        h2=((h2+(s[r]-'a'+1))*p1)%r1;
        h4=((h4+(s[r]-'a'+1))*p2)%r2;
        l++;r--;
    }
    ans+=2;
    if (l<=r)
        solve(l,r);
}
int main() {
    cin>>t;
    while (cin>>s) {
        ans=0;
        solve(0,s.length()-1);
        cout<<ans<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 8 ms 504 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 8 ms 504 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 628 ms 11228 KB Output is correct
15 Correct 342 ms 6632 KB Output is correct
16 Correct 591 ms 10600 KB Output is correct
17 Correct 328 ms 6064 KB Output is correct