# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
112437 | 2019-05-19T19:14:52 Z | Akashi | 회문 (APIO14_palindrome) | C++14 | 111 ms | 66732 KB |
#include <bits/stdc++.h> using namespace std; struct Node{ vector <int> v; int son[26]; int num, length, link; }; Node PalTree[300005]; char s[300005]; void initialize_tree(){ PalTree[1].length = -1; PalTree[1].link = 1; PalTree[2].length = 0; PalTree[2].link = 1; } int Last = 2, tree_size = 2; void add_letter(int pos){ char ch = s[pos] - 'a'; while(true){ if(pos - PalTree[Last].length - 1 >= 0 && s[pos] == s[pos - PalTree[Last].length - 1]) break ; Last = PalTree[Last].link; } if(PalTree[Last].son[ch]){ PalTree[PalTree[Last].son[ch]].num++; Last = PalTree[Last].son[ch]; return ; } int cur = ++tree_size; PalTree[Last].son[ch] = cur; PalTree[cur].length = PalTree[Last].length + 2; PalTree[cur].num = 1; if(Last == 1){ PalTree[2].v.push_back(cur); PalTree[cur].link = 2; Last = cur; return ; } while(true){ Last = PalTree[Last].link; if(pos - PalTree[Last].length - 1 >= 0 && s[pos] == s[pos - PalTree[Last].length - 1]){ PalTree[cur].link = PalTree[Last].son[ch]; PalTree[PalTree[cur].link].v.push_back(cur); break ; } } Last = cur; } long long Sol = 0; void dfs(int nod = 2){ for(auto it : PalTree[nod].v){ dfs(it); PalTree[nod].num += PalTree[it].num; } Sol = max(Sol, 1LL * PalTree[nod].length * PalTree[nod].num); } int main() { // freopen("palindrome.in", "r", stdin); // freopen("palindrome.out", "w", stdout); initialize_tree(); scanf("%s", s); int L = strlen(s); for(int i = 0; i < L ; ++i) add_letter(i); dfs(); printf("%lld", Sol); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 42616 KB | Output is correct |
2 | Correct | 32 ms | 42624 KB | Output is correct |
3 | Correct | 32 ms | 42624 KB | Output is correct |
4 | Correct | 34 ms | 42616 KB | Output is correct |
5 | Correct | 32 ms | 42512 KB | Output is correct |
6 | Correct | 32 ms | 42504 KB | Output is correct |
7 | Correct | 32 ms | 42616 KB | Output is correct |
8 | Correct | 31 ms | 42616 KB | Output is correct |
9 | Correct | 32 ms | 42624 KB | Output is correct |
10 | Correct | 32 ms | 42616 KB | Output is correct |
11 | Correct | 33 ms | 42624 KB | Output is correct |
12 | Correct | 33 ms | 42624 KB | Output is correct |
13 | Correct | 33 ms | 42616 KB | Output is correct |
14 | Correct | 32 ms | 42576 KB | Output is correct |
15 | Correct | 32 ms | 42624 KB | Output is correct |
16 | Correct | 32 ms | 42616 KB | Output is correct |
17 | Correct | 31 ms | 42624 KB | Output is correct |
18 | Correct | 32 ms | 42624 KB | Output is correct |
19 | Correct | 32 ms | 42616 KB | Output is correct |
20 | Correct | 33 ms | 42624 KB | Output is correct |
21 | Correct | 32 ms | 42744 KB | Output is correct |
22 | Correct | 32 ms | 42744 KB | Output is correct |
23 | Correct | 33 ms | 42624 KB | Output is correct |
24 | Correct | 32 ms | 42624 KB | Output is correct |
25 | Correct | 32 ms | 42748 KB | Output is correct |
26 | Correct | 32 ms | 42616 KB | Output is correct |
27 | Correct | 32 ms | 42624 KB | Output is correct |
28 | Correct | 33 ms | 42616 KB | Output is correct |
29 | Correct | 32 ms | 42608 KB | Output is correct |
30 | Correct | 33 ms | 42612 KB | Output is correct |
31 | Correct | 31 ms | 42616 KB | Output is correct |
32 | Correct | 33 ms | 42656 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 42624 KB | Output is correct |
2 | Correct | 32 ms | 42624 KB | Output is correct |
3 | Correct | 32 ms | 42740 KB | Output is correct |
4 | Correct | 34 ms | 42596 KB | Output is correct |
5 | Correct | 32 ms | 42616 KB | Output is correct |
6 | Correct | 33 ms | 42752 KB | Output is correct |
7 | Correct | 33 ms | 42616 KB | Output is correct |
8 | Correct | 33 ms | 42616 KB | Output is correct |
9 | Correct | 32 ms | 42624 KB | Output is correct |
10 | Correct | 32 ms | 42624 KB | Output is correct |
11 | Correct | 32 ms | 42616 KB | Output is correct |
12 | Correct | 34 ms | 42616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 43100 KB | Output is correct |
2 | Correct | 34 ms | 43112 KB | Output is correct |
3 | Correct | 36 ms | 43392 KB | Output is correct |
4 | Correct | 34 ms | 43392 KB | Output is correct |
5 | Correct | 33 ms | 42744 KB | Output is correct |
6 | Correct | 35 ms | 42880 KB | Output is correct |
7 | Correct | 35 ms | 43008 KB | Output is correct |
8 | Correct | 33 ms | 42624 KB | Output is correct |
9 | Correct | 35 ms | 42624 KB | Output is correct |
10 | Correct | 34 ms | 42744 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 48376 KB | Output is correct |
2 | Correct | 53 ms | 47224 KB | Output is correct |
3 | Correct | 54 ms | 50680 KB | Output is correct |
4 | Correct | 56 ms | 49072 KB | Output is correct |
5 | Correct | 47 ms | 44024 KB | Output is correct |
6 | Correct | 44 ms | 44664 KB | Output is correct |
7 | Correct | 48 ms | 45788 KB | Output is correct |
8 | Correct | 35 ms | 42744 KB | Output is correct |
9 | Correct | 38 ms | 44536 KB | Output is correct |
10 | Correct | 44 ms | 43776 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 96 ms | 59640 KB | Output is correct |
2 | Correct | 106 ms | 54520 KB | Output is correct |
3 | Correct | 106 ms | 66732 KB | Output is correct |
4 | Correct | 90 ms | 57700 KB | Output is correct |
5 | Correct | 97 ms | 47608 KB | Output is correct |
6 | Correct | 82 ms | 53240 KB | Output is correct |
7 | Correct | 95 ms | 51704 KB | Output is correct |
8 | Correct | 39 ms | 43256 KB | Output is correct |
9 | Correct | 38 ms | 43228 KB | Output is correct |
10 | Correct | 82 ms | 46844 KB | Output is correct |
11 | Correct | 111 ms | 54904 KB | Output is correct |
12 | Correct | 43 ms | 45304 KB | Output is correct |