Submission #850869

# Submission time Handle Problem Language Result Execution time Memory
850869 2023-09-17T15:18:09 Z dungz Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
92 ms 20748 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll const MOD=1e9+9,base=31;
ll p[1000005];
void sol()
{
    string s;
    cin>>s;
    s=" "+s;
    int i=1,j=s.size()-1;
    ll hash1=0,hash2=0;
    int d=0,ans=0;
    p[0]=1;
    for(int i=1;i<=s.size()-1;i++)
    {
        p[i]=(p[i-1]*base)%MOD;
    }
    int flag=1;
    for(int step=1;step<=s.size()/2-(s.size()%2==0?1:0);step++)
    {
        hash1=(hash1*base+s[i]-'a'+1)%MOD;
        hash2=(hash2+(s[j]-'a'+1)*p[d])%MOD;
        flag=1;
        if(hash1==hash2)
        {
            flag=0;
            hash1=0;
            hash2=0;
            ans+=2;
            d=-1;
        }
        d++;
        i++,j--;
    }
    if(s.size()%2==1) cout<<ans+flag<<endl;
    else cout<<ans+1<<endl;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
   
    int t;
    cin>>t;
    while(t--)
    {
        sol();
    }
}

Compilation message

palindromic.cpp: In function 'void sol()':
palindromic.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i=1;i<=s.size()-1;i++)
      |                 ~^~~~~~~~~~~~
palindromic.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int step=1;step<=s.size()/2-(s.size()%2==0?1:0);step++)
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 636 KB Output is correct
14 Correct 92 ms 20748 KB Output is correct
15 Correct 50 ms 15560 KB Output is correct
16 Correct 91 ms 19588 KB Output is correct
17 Correct 49 ms 11128 KB Output is correct