# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
621139 | socpite | 회문 (APIO14_palindrome) | C++14 | 63 ms | 66624 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
const int maxn = 3e5+5;
int cnt = 2;
int lnk[maxn], go[maxn][26], len[maxn];
ll dp[maxn];
ll ans = 0;
vector<int> tree[maxn];
string str;
void dfs(int x){
for(auto v: tree[x]){
dfs(v);
dp[x]+=dp[v];
}
ans = max(ans, dp[x]*len[x]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> str;
str = '#'+str;
len[0]=-1;
len[1]=0;
int crr = 1;
for(int i = 1; i < str.length(); i++){
int id = str[i]-'a';
while(crr && str[i] != str[i-len[crr]-1])crr = lnk[crr];
if(go[crr][id])crr = go[crr][id];
else{
int tmp = lnk[crr];
while(tmp && str[i] != str[i-len[tmp]-1])tmp = lnk[tmp];
if(!go[tmp][id])lnk[cnt]=1;
else lnk[cnt]=go[tmp][id];
go[crr][id]=cnt;
len[cnt]=len[crr]+2;
crr = cnt;
cnt++;
}
dp[crr]++;
}
for(int i = 1; i < cnt; i++)tree[lnk[i]].push_back(i);
dfs(0);
cout << ans;
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |