# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
205589 | mihai50000 | 회문 (APIO14_palindrome) | C++17 | 5 ms | 376 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
ifstream fin("palindrome.in");
ofstream fout("palindrome.out");
#define int long long
struct PalTree
{
struct Node
{
map <char, int> next;
int link;
int len;
int cnt;
};
vector <Node> T;
int n = 2;
int ans = 0;
PalTree(string str) : T(str.size() + 2)
{
T[1].link = T[1].len = 0;
T[0].link = T[0].len = -1;
int last = 0;
int m = str.size();
for(int i = 0; i < m; ++i)
{
char ch = str[i];
int nod = last;
while(ch != str[i - 1 - T[nod].len])
nod = T[nod].link;
if(T[nod].next.count(ch))
{
nod = T[nod].next[ch];
T[nod].cnt++;
last = nod;
continue;
}
int act = n++;
T[act].len = T[nod].len + 2;
T[nod].next[ch] = act;
int link = T[nod].link;
while(link != -1)
{
if(ch == str[i - T[link].len - 1] && T[link].next.count(ch))
{
link = T[link].next[ch];
break;
}
link = T[link].link;
}
if(link <= 0)
link = 1;
T[act].link = 1;
T[act].cnt = 1;
last = act;
}
for(int i = n - 1; i > 0; --i)
{
T[T[i].link].cnt += T[i].cnt;
ans = max(ans, T[i].cnt * T[i].len);
}
}
};
main()
{
string s;
fin >> s;
PalTree arb(s);
fout << arb.ans << '\n';
}
컴파일 시 표준 에러 (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... |