Submission #863875

# Submission time Handle Problem Language Result Execution time Memory
863875 2023-10-21T09:57:13 Z tradz Palinilap (COI16_palinilap) C++14
0 / 100
12 ms 4700 KB
// Author : Hoang Van Tra - HSGS Bac Giang
// Train VOI 2023 - 2024

#include <bits/stdc++.h>

using namespace std;

// -------------------------------------------------------INDEF-----------------------------------------------------------------------

#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())
const int M = 1e9+7;
const ll oo = 1e18;
const int block = 708;
namespace IO
{
    #define getchar() (ipos==iend and (iend=(ipos=_ibuf)+fread(_ibuf,1,__bufsize,stdin),ipos==iend)?EOF:*ipos++)
    #define putchar(ch) (opos==oend?fwrite(_obuf,1,__bufsize,stdout),opos=_obuf:0,*opos++=(ch))
    #define __bufsize (1<<20)
    char _ibuf[__bufsize],_obuf[__bufsize],_stk[20];
    char *ipos=_ibuf,*iend=_ibuf,*opos=_obuf,*oend = _obuf+__bufsize,*stkpos = _stk;
    struct END{~END(){fwrite(_obuf,1,opos-_obuf,stdout);}}__;
    inline void read(int&x)
    {
        register int f=0,ch;
        for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
        for(x=0;isdigit(ch);ch=getchar())x=(x<<3ll)+(x<<1ll)+(ch^48);
        x=f?-x:x;
    }
    inline void readll(ll&x)
    {
        register ll f=0,ch;
        for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
        for(x=0;isdigit(ch);ch=getchar())x=(x<<3ll)+(x<<1ll)+(ch^48);
        x=f?-x:x;
    }
    inline void write(ll x)
    {
        if(x<0)putchar('-'),x=-x;
        while(*++stkpos=x%10^48,x/=10,x);
        while(stkpos!=_stk)putchar(*stkpos--);
    }
};

using namespace IO;

string s;
int n;
namespace sub2
{
    const int N = 5005;
    bool f[N][N];
    ll ans = 0;

    ll sol() {
        int tmp = 0;
        For(i, 1, n) For(j, 1, n) f[i][j] = 0;
        Ford(i, n, 1) {
            f[i][i] = 1;
            if(s[i] == s[i + 1]) f[i][i + 1] = 1;
            For(j, i + 2, n) {
                if(s[i] == s[j]) f[i][j] = f[i + 1][j - 1];
            }
        }

        For(i, 1, n) For(j, i, n) tmp = tmp + f[i][j];
        return tmp;
    }

    void solve() {
        ans = sol();
        For(i, 1, n) {
            char x = s[i];
            For(j, 0, 25) {
                if(j == x - 'a') continue;
                s[i] = char('a' + j);
                ans = max(ans, sol());
            }
            s[i] = x;
        }
        cout << ans;
    }
}
// -------------------------------------------------------ENDEF----------------------------------------------------------------------

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);


    cin >> s;
    n = s.size();
    if(n <= 500) {
    	sub2 :: solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 4700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -