# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
77647 | samuelfgs96 | 회문 (APIO14_palindrome) | C++11 | 73 ms | 55944 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
const int N = 212345;
typedef pair<int, int> pii;
typedef long long ll;
int bit[N];
struct treez {
struct Node {
int start, end;
int length;
int insertEdg[26];
int suffixEdg;
int qtd;
};
Node root1, root2;
Node tree[N];
int currNode;
string s;
int ptr;
treez () { }
treez (string s) : s(s) {
root1.length = -1;
root1.suffixEdg = 1;
root2.length = 0;
root2.suffixEdg = 1;
memset (tree, 0, sizeof tree);
tree[1] = root1;
tree[2] = root2;
ptr = 2;
currNode = 1;
for (int i = 0; i < s.size(); i++) insert(i);
}
void insert(int idx) {
int tmp = currNode;
while (true) {
int curLength = tree[tmp].length;
if (idx - curLength >= 1 and s[idx] == s[idx-curLength-1])
break;
tmp = tree[tmp].suffixEdg;
}
if(tree[tmp].insertEdg[s[idx]-'a'] != 0) {
currNode = tree[tmp].insertEdg[s[idx]-'a'];
tree[currNode].qtd++;
return;
}
ptr++;
tree[tmp].insertEdg[s[idx]-'a'] = ptr;
tree[ptr].length = tree[tmp].length + 2;
tree[ptr].end = idx;
tree[ptr].start = idx - tree[ptr].length + 1;
tree[ptr].qtd = 1;
tmp = tree[tmp].suffixEdg;
currNode = ptr;
if (tree[currNode].length == 1) {
tree[currNode].suffixEdg = 2;
return;
}
while (true) {
int curLength = tree[tmp].length;
if (idx-curLength >= 1 and s[idx] == s[idx-curLength-1])
break;
tmp = tree[tmp].suffixEdg;
}
tree[currNode].suffixEdg = tree[tmp].insertEdg[s[idx]-'a'];
}
};
treez t1;
string s;
ll ans;
int sz[N];
void dfs (int u) {
for (int i = t1.ptr; i >= 3; i--) {
sz[i] += t1.tree[i].qtd;
sz[t1.tree[i].suffixEdg] += sz[i];
}
}
void dfs2 (int u) {
for (int i = 0; i < 26; i++)
if (t1.tree[u].insertEdg[i])
dfs2(t1.tree[u].insertEdg[i]);
if (u >= 3) {
ans = max(ans, ll(sz[u]) * (t1.tree[u].end - t1.tree[u].start + 1));
}
}
int main (void) {
cin >> s;
t1 = treez(s);
dfs(1);
dfs2(1);
dfs2(2);
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (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... |