답안 #616819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
616819 2022-08-01T07:00:36 Z Je_O Palinilap (COI16_palinilap) C++17
54 / 100
1000 ms 41300 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 5;
ll add[N][26];
ll prv[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;
        int cur_cnt = 0;
        while(l >= 0 && r < n && s[l] == s[r]){
            ++cur_cnt;
            --l; ++r;
        }
        cnt += cur_cnt;
        int cur_l = l, cur_r = r;
        cur_cnt = 0;
        while(cur_l + 2 < cur_r){
            ++cur_l; --cur_r;
            ++cur_cnt;
            prv[cur_l][s[cur_l] - 'a'] += cur_cnt;
            prv[cur_r][s[cur_r] - 'a'] += cur_cnt;
        }
        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;
        int cur_cnt = 0;
        while(l >= 0 && r < n && s[l] == s[r]){
            ++cur_cnt;
            --l; ++r;
        }
        cnt += cur_cnt;
        int cur_l = l, cur_r = r;
        cur_cnt = 0;
        while(cur_l + 2 < cur_r){
            ++cur_l; --cur_r;
            ++cur_cnt;
            prv[cur_l][s[cur_l] - 'a'] += cur_cnt;
            prv[cur_r][s[cur_r] - 'a'] += cur_cnt;
        }
        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] - prv[i][s[i] - 'a']);
        }
    }
    cout << cnt + max_add << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 2368 KB Output is correct
2 Correct 139 ms 2368 KB Output is correct
3 Correct 5 ms 2388 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 2004 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 41300 KB Output is correct
2 Execution timed out 1085 ms 12888 KB Time limit exceeded
3 Halted 0 ms 0 KB -