Submission #1313550

#TimeUsernameProblemLanguageResultExecution timeMemory
1313550user184Palindromic Partitions (CEOI17_palindromic)C++20
100 / 100
33 ms1492 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    ll hasz = 0, odhasz = 0, mod = 1e9+7, mnoz = 29, ile = 1, ilete, odp = 0, os = -1;
    cin >> ilete ; 
    for( int i = 0 ; i < ilete ; ++i ){
        cin >> s;
        odp = 0; hasz = 0; odhasz = 0; ile = 1;
        for( int j = 0 ; j < s.size()/2 ; ++j ){
            hasz += ile*(s[j]-96);
            odhasz *= mnoz;
            odhasz += s[s.size()-j-1]-96;
            ile *= mnoz;
            ile %= mod;
            hasz %= mod;
            odhasz %= mod;
            if( hasz == odhasz ){
                odp +=  2;
                os = j ;
                hasz = 0;
                odhasz = 0;
                ile = 1;
            }
        }
        if( hasz > 0 || (s.size()%2) )
            odp++;
        cout << odp << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...