# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
863873 | tradz | Palinilap (COI16_palinilap) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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;
}