Submission #312030

# Submission time Handle Problem Language Result Execution time Memory
312030 2020-10-12T07:36:55 Z FatihSolak Palinilap (COI16_palinilap) C++14
0 / 100
1000 ms 21632 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    long long ans=0;
    int l=s.length();
    long long arr[l][26];
    long long brr[l];
    for(int i=0;i<l;i++){
        for(int j=0;j<26;j++){
            arr[i][j]=0; 
        }
        brr[i]=0;
    }
    for(int i=0;i<l;i++){
        for(int j=i;j<l;j++){
            string a="";
            for(int c=i;c<=j;c++){
                a +=s[c];
            }
            string b=a;
            reverse(a.begin(),a.end());
            if(b == a){
                ans++;
                for(int c=i;c<=j;c++){
                    brr[c]++;
                }
            }
            else{
                for(int h=0;h<(j-i+1)/2;h++){
                    if(b[h] != a[h]){
                        string d ="";
                        for(int c=i;c<=j;c++){
                            if(c == i+h || c == j-h){
                                continue;
                            }
                            d+=s[c];
                        }
                        string e=d;
                        reverse(d.begin(),d.end());
                        if(d==e){
                            arr[i+h][a[h]-'a']++;
                            arr[j-h][b[h]-'a']++;
                            //cout << i<< " " << j << " "<<  i+h <<" " << a[h] << " " << j-h  << " " << b[h]<< endl;
                        }
                    }
                }
            }
        }
    }
    //cout <<endl;
    long long maxi=0;
    for(int i=0;i<l;i++){
        for(int j=0;j<26;j++){
            if(brr[i] <=arr[i][j]){
                maxi = max(maxi,arr[i][j]-brr[i]+1);
            }
            //cout << arr[i][j] <<" ";
        }
        //cout <<endl;
    }
    cout << maxi +ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 1408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1048 ms 21632 KB Time limit exceeded
2 Halted 0 ms 0 KB -