# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
666431 | Felicity | Palinilap (COI16_palinilap) | C++14 | 1092 ms | 720 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(ll i=a;i<=b;++i)
#define ar array
#define pb push_back
#define e0 exit(0)
#define ConVitKeu QuacQuac
using namespace std;
const int N=5e3+5;
const ll mo=1e9+7;
int dp[5005][5005],n,dp1[5005][5005];
string ss,t;
const int maxn = 5005;
char str[maxn];
char s[maxn*2];
int p[maxn*2];
int len;
ll Manacher(){
int i;
s[0] = '$';
s[1] = '#';
len = strlen(str);
//define s from str
for(i=0; i<len; i++) {
s[i*2 +2] = str[i];
s[i*2 +3] = '#';
}
len = i*2+2;
s[len] = '\0';
int MaxL, id = 0;
MaxL =0;
memset(p,0,sizeof(p));
for(int i=0; i<len; i++) {
if(p[id] + id > i)
p[i] = min(p[2*id-i], p[id] + id -i);
else
p[i] = 1;
while(s[i+p[i]] == s[i-p[i]])
p[i]++;
if(p[i] + i > p[id]+id) {
id = i;
}
MaxL += p[i]/2;
}
return MaxL;
}
ll tinh(string s){
f(i,1,n)f(j,1,n)dp[i][j]=0,dp1[i][j]=0;
f(i,1,n){
f(j,1,i){
if(i==j)dp[j][i]=1;
else{
if(s[i]==s[j]){
if(i==j+1)dp[j][i]=1;
else dp[j][i]=dp[j+1][i-1];
}
}
}
}
f(i,1,n){
f(j,1,n){
dp1[i][j]=dp1[i-1][j]+dp1[i][j-1]+dp[i][j]-dp1[i-1][j-1];
}
}
ll l=1,r=n;
return dp1[r][r]-dp1[r][l-1]-dp1[l-1][r]+dp1[l-1][l-1];
}
char a[N], b[2 * N];
void solve(){
ll res=0;
cin>>str;
f(i,0,strlen(str)-1){
a[i]=str[i];
}
f(i,1,strlen(str)){
f(j,0,strlen(a)-1){
str[j]=a[j];
}
f(j,1,26){
str[i-1]=char(j+'a'-1);
res=max(res,Manacher());
}
}
cout<<res;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("DEBT.INP","r",stdin);
//freopen("DEBT.OUT","w",stdout);
int t;
t=1;
//cin>>t;
while(t--){
solve();
}
}
/*
6
3 2 1 5 2 4
1 3
2 4
1 5
2 1
3 6
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |