Submission #863873

# Submission time Handle Problem Language Result Execution time Memory
863873 2023-10-21T09:55:33 Z tradz Palinilap (COI16_palinilap) C++14
Compilation error
0 ms 0 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  N = 1e6+7;
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;
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);

    #define TASK ""
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

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

    return 0;
}

Compilation message

palinilap.cpp: In function 'long long int sub2::sol()':
palinilap.cpp:63:19: error: 'n' was not declared in this scope
   63 |         For(i, 1, n) For(j, 1, n) f[i][j] = 0;
      |                   ^
palinilap.cpp:10:40: note: in definition of macro 'For'
   10 | #define For(i,a,b) for(int i = a; i <= b; i++)
      |                                        ^
palinilap.cpp:64:17: error: 'n' was not declared in this scope
   64 |         Ford(i, n, 1) {
      |                 ^
palinilap.cpp:11:33: note: in definition of macro 'Ford'
   11 | #define Ford(i,a,b) for(int i = a; i >= b; i--)
      |                                 ^
palinilap.cpp:72:19: error: 'n' was not declared in this scope
   72 |         For(i, 1, n) For(j, i, n) tmp = tmp + f[i][j];
      |                   ^
palinilap.cpp:10:40: note: in definition of macro 'For'
   10 | #define For(i,a,b) for(int i = a; i <= b; i++)
      |                                        ^
palinilap.cpp: In function 'void sub2::solve()':
palinilap.cpp:78:19: error: 'n' was not declared in this scope
   78 |         For(i, 1, n) {
      |                   ^
palinilap.cpp:10:40: note: in definition of macro 'For'
   10 | #define For(i,a,b) for(int i = a; i <= b; i++)
      |                                        ^
palinilap.cpp: In function 'int32_t main()':
palinilap.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palinilap.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~