Submission #936050

# Submission time Handle Problem Language Result Execution time Memory
936050 2024-03-01T05:00:39 Z Aiperiii Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
10000 ms 344 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
vector <int> mp[130];
signed main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string t=s;
        reverse(all(t));
        int ans=0;
        for(int i=0;i<s.size();i++){
            mp[(int)s[i]].pb(i);
        }
        for(int i=0;i<t.size();i++){
            if(s[i]==t[i])ans++;
            else{
                auto pos=upper_bound(all(mp[(int)t[i]]),i)-mp[(int)t[i]].begin();
                for(int j=pos;j<mp[(int)t[i]].size();j++){
                    bool ok=1;
                    int x=0;
                    for(int k=i;k<=mp[(int)t[i]][j];k++){
                        if(t[k]!=s[mp[(int)t[i]][j]-x]){
                            ok=0;break;
                        }
                        x++;
                    }
                    if(ok){
                        ans++;
                        i=mp[(int)t[i]][j];
                        break;
                    }
                }
            }
        }
        cout<<ans<<"\n";
    }
}
/*
4
bonobo
deleted
racecar
racecars
 */

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:18:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for(int i=0;i<s.size();i++){
      |                     ~^~~~~~~~~
palindromic.cpp:21:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int i=0;i<t.size();i++){
      |                     ~^~~~~~~~~
palindromic.cpp:25:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |                 for(int j=pos;j<mp[(int)t[i]].size();j++){
      |                               ~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 10090 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10090 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10090 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10090 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -