Submission #312043

# Submission time Handle Problem Language Result Execution time Memory
312043 2020-10-12T08:15:19 Z FatihSolak Palinilap (COI16_palinilap) C++14
0 / 100
1000 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
string s;
long long solve(){
    long long ans=0;
    int l=s.length();
    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++;
            }
        }
    }
    return ans;
}
int main(){
    cin >> s;
    long long maxi=0;
    int l=s.length();
    for(int i=0;i<l;i++){
        char now=s[i];
        for(int j=0;j<26;j++){
            s[i] = j+'a';
            maxi = max(maxi, solve());
        }
        s[i] = now;
    }
    cout << maxi;
    /*
    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]=1; 
        }
        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(j-i%2 == 0){
                for(int c=0;c<26;c++){
                    if(c!=s[(i+j)/2]-'a'){
                        arr[(i+j)/2][c]++;
                    }
                }
            }
            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]);
            }
            cout << arr[i][j] <<" ";
        }
        cout <<endl;
    }
    cout << maxi +ans;*/
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -