# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
205620 | mihai50000 | 회문 (APIO14_palindrome) | C++17 | 58 ms | 44816 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct PalTree
{
struct Node
{
map <char, int> urm;
int len;
int cnt;
int fail;
};
int n = 2;
int ans = 0;
vector <Node> vec;
PalTree(string s) : vec(s.size() + 2)
{
vec[0].fail = vec[0].len = -1;
vec[1].fail = vec[1].len = 0;
int last = 0;
for(int i = 0; i < s.size(); ++i)
{
char ch = s[i];
int pos = last;
while(s[i - vec[pos].len - 1] != ch)
{
pos = vec[pos].fail;
}
if(vec[pos].urm.count(ch))
{
pos = vec[pos].urm[ch];
vec[pos].cnt++;
last = pos;
continue;
}
vec[n].cnt = 1;
vec[n].len = vec[pos].len + 2;
vec[pos].urm[ch] = n;
int fail = vec[pos].fail;
while(fail != -1 && !(s[i - 1 - vec[fail].len] == ch && vec[fail].urm.count(ch)))
{
fail = vec[fail].fail;
}
if(vec[fail].urm.count(ch))
fail = vec[fail].urm[ch];
if(fail < 1)
fail = 1;
vec[n].fail = fail;
last = n;
n++;
}
for(int i = n - 1; i > 0; --i)
{
vec[vec[i].fail].cnt += vec[i].cnt;
ans = max(ans, vec[i].cnt * vec[i].len);
}
}
};
main()
{
string s;
cin >> s;
PalTree arb(s);
cout << 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... |