Submission #578972

#TimeUsernameProblemLanguageResultExecution timeMemory
578972webPalindromic Partitions (CEOI17_palindromic)C++17
60 / 100
10086 ms8888 KiB
#include <iostream>
#include <vector>

using namespace std;

bool equalStr(string& s, int p1, int p2, int ctr)
{
    if(s[p1] != s[p2] || s[p1+ctr] != s[p2+ctr] )
        return false;
    return s.substr(p1, ctr+1) == s.substr(p2, ctr+1);
}
int main()
{
    int t; cin>>t;

    while(t--)
    {
        string s; cin>>s;
        int ptr1 = 0, ptr2= s.length() -1;
        long long res = 0;
        int ctr = 0;
        while(ptr1 <= ptr2)
        {
            
            if(s[ptr1] == s[ptr2])
            {
                if(equalStr(s, ptr1, ptr2, ctr))
                {
                    res++;
                    if(ptr1 != ptr2)
                        res++;
                    ptr1 += ctr+1;
                    ptr2--;
                    ctr =0;
                }
                else
                {
                    ptr2--;
                    ctr++;
                }
            }
            else
            {
                ptr2--;
                ctr++;
            }
        }   
        cout<<res<<endl;    
    }

    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...