Submission #616749

# Submission time Handle Problem Language Result Execution time Memory
616749 2022-08-01T06:37:00 Z Je_O Palinilap (COI16_palinilap) C++17
0 / 100
18 ms 20996 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 5;
ll add[N][26];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s; cin >> s;
    int n = s.length();
    ll cnt = 0;
    for(int i = 0; i < n; ++i){
        int l = i, r = i;
        while(l >= 0 && r < n && s[l] == s[r]){
            ++cnt;
            --l; ++r;
        }
        int lf = l, rg = r;
        int cnt_add = 0;
        while(l >= 0 && r < n){
            --l; ++r;
            ++cnt_add;
            if(s[l] != s[r])break;
        }
        if(cnt_add){
            add[lf][s[rg] - 'a'] += cnt_add;
            add[rg][s[lf] - 'a'] += cnt_add;
        }
    }
    for(int i = 1; i < n; ++i){
        int l = i - 1, r = i;
        while(l >= 0 && r < n && s[l] == s[r]){
            ++cnt;
            --l; ++r;
        }
        int lf = l, rg = r;
        int cnt_add = 0;
        while(l >= 0 && r < n){
            --l; ++r;
            ++cnt_add;
            if(s[l] != s[r])break;
        }
        if(cnt_add){
            add[lf][s[rg] - 'a'] += cnt_add;
            add[rg][s[lf] - 'a'] += cnt_add;
        }
    }
    ll max_add = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 26; ++j){
            max_add = max(max_add, add[i][j]);
        }
    }
    cout << cnt + max_add << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1364 KB Output is correct
2 Incorrect 11 ms 1368 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 20996 KB Output isn't correct
2 Halted 0 ms 0 KB -