Submission #560896

# Submission time Handle Problem Language Result Execution time Memory
560896 2022-05-12T04:40:58 Z Yazan_Alattar Palinilap (COI16_palinilap) C++14
0 / 100
282 ms 67928 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 5007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

string s;
int cnt[M][30], dp[M][M], con[M], ans;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    int n = s.size(); s = '#' + s;

    for(int mid = 1; mid <= n; ++mid){
        int l = mid, r = mid;
        int pos1 = 0, pos2 = 0, c1 = 0, c2 = 0;
        while(l && r <= n){
            if(s[l] != s[r]){
                if(pos1) break;

                pos1 = l;
                pos2 = r;
                c1 = s[r] - 'a';
                c2 = s[l] - 'a';
            }

            ++cnt[pos1][c1];
            ++cnt[pos2][c2];
            if(pos1 == 0) ++ans;

            --l; ++r;
        }


        l = mid, r = mid + 1;
        pos1 = 0; pos2 = 0; c1 = 0; c2 = 0;
        while(l && r <= n){
            if(s[l] != s[r]){
                if(pos1) break;

                pos1 = l;
                pos2 = r;
                c1 = s[r] - 'a';
                c2 = s[l] - 'a';
            }

            ++cnt[pos1][c1];
            ++cnt[pos2][c2];
            if(pos1 == 0) ++ans;

            --l; ++r;
        }
    }

    for(int mid = 1; mid <= n; ++mid){
        int l = mid, r = mid;

        while(l && r <= n){
            if(s[l] != s[r]) break;
            if(l < r) ++dp[l][r];
            --l; ++r;
        }

        l = mid, r = mid + 1;
        while(l && r <= n){
            if(s[l] != s[r]) break;
            ++dp[l][r];
            --l; ++r;
        }
    }

    for(int len = n; len; --len){
        for(int l = 1; l + len - 1 <= n; ++l){
            int r = l + len - 1;
            dp[l][r] += dp[l - 1][r + 1];

            con[l] += dp[l][r];
            con[r] += dp[l][r];
        }
    }

    int mx = 0;
    for(int i = 1; i <= n; ++i) for(int j = 0; j < 26; ++j) mx = max(mx, cnt[i][j] - con[i]);
    cout << ans + mx << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 282 ms 67928 KB Output is correct
2 Correct 282 ms 67916 KB Output is correct
3 Correct 146 ms 67864 KB Output is correct
4 Incorrect 53 ms 30376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2128 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -