# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
253632 | 2020-07-28T13:20:43 Z | dolphingarlic | Palindromes (APIO14_palindrome) | C++14 | 69 ms | 69628 KB |
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; struct Node { int nxt[26], sufflink; ll len, cnt; vector<int> edges; } tree[303030]; string s; int suff, num; ll ans = 0; void add_letter(int pos) { int curr = suff, curr_len = 0; int letter = s[pos] - 'a'; while (true) { curr_len = tree[curr].len; if (pos - 1 - curr_len > -1 && s[pos - 1 - curr_len] == s[pos]) break; curr = tree[curr].sufflink; } if (tree[curr].nxt[letter]) { suff = tree[curr].nxt[letter]; tree[suff].cnt++; return; } suff = ++num; tree[num].len = tree[curr].len + 2; tree[num].cnt = 1; tree[curr].nxt[letter] = num; if (tree[num].len == 1) { tree[num].sufflink = 2; tree[2].edges.push_back(num); return; } while (true) { curr = tree[curr].sufflink; curr_len = tree[curr].len; if (pos - 1 - curr_len > -1 && s[pos - 1 - curr_len] == s[pos]) { tree[num].sufflink = tree[curr].nxt[letter]; tree[tree[curr].nxt[letter]].edges.push_back(num); break; } } } void init() { num = 2, suff = 2; tree[1].len = -1, tree[1].sufflink = 1; tree[2].len = 0, tree[2].sufflink = 1; tree[1].edges.push_back(2); } void dfs(int node = 1) { for (int i : tree[node].edges) { dfs(i); tree[node].cnt += tree[i].cnt; } ans = max(ans, tree[node].len * tree[node].cnt); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s; init(); FOR(i, 0, s.size()) add_letter(i); dfs(); cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 45440 KB | Output is correct |
2 | Correct | 21 ms | 45440 KB | Output is correct |
3 | Correct | 21 ms | 45440 KB | Output is correct |
4 | Correct | 21 ms | 45440 KB | Output is correct |
5 | Correct | 21 ms | 45440 KB | Output is correct |
6 | Correct | 21 ms | 45440 KB | Output is correct |
7 | Correct | 22 ms | 45440 KB | Output is correct |
8 | Correct | 26 ms | 45440 KB | Output is correct |
9 | Correct | 21 ms | 45440 KB | Output is correct |
10 | Correct | 21 ms | 45440 KB | Output is correct |
11 | Correct | 21 ms | 45440 KB | Output is correct |
12 | Correct | 21 ms | 45564 KB | Output is correct |
13 | Correct | 21 ms | 45432 KB | Output is correct |
14 | Correct | 29 ms | 45440 KB | Output is correct |
15 | Correct | 27 ms | 45440 KB | Output is correct |
16 | Correct | 26 ms | 45440 KB | Output is correct |
17 | Correct | 26 ms | 45432 KB | Output is correct |
18 | Correct | 25 ms | 45432 KB | Output is correct |
19 | Correct | 25 ms | 45440 KB | Output is correct |
20 | Correct | 22 ms | 45440 KB | Output is correct |
21 | Correct | 22 ms | 45560 KB | Output is correct |
22 | Correct | 21 ms | 45440 KB | Output is correct |
23 | Correct | 21 ms | 45440 KB | Output is correct |
24 | Correct | 22 ms | 45440 KB | Output is correct |
25 | Correct | 24 ms | 45344 KB | Output is correct |
26 | Correct | 26 ms | 45448 KB | Output is correct |
27 | Correct | 21 ms | 45440 KB | Output is correct |
28 | Correct | 22 ms | 45440 KB | Output is correct |
29 | Correct | 23 ms | 45440 KB | Output is correct |
30 | Correct | 21 ms | 45440 KB | Output is correct |
31 | Correct | 22 ms | 45440 KB | Output is correct |
32 | Correct | 22 ms | 45440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 45440 KB | Output is correct |
2 | Correct | 29 ms | 45440 KB | Output is correct |
3 | Correct | 26 ms | 45440 KB | Output is correct |
4 | Correct | 22 ms | 45440 KB | Output is correct |
5 | Correct | 28 ms | 45440 KB | Output is correct |
6 | Correct | 25 ms | 45440 KB | Output is correct |
7 | Correct | 22 ms | 45440 KB | Output is correct |
8 | Correct | 25 ms | 45440 KB | Output is correct |
9 | Correct | 21 ms | 45440 KB | Output is correct |
10 | Correct | 21 ms | 45440 KB | Output is correct |
11 | Correct | 25 ms | 45440 KB | Output is correct |
12 | Correct | 22 ms | 45440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 45952 KB | Output is correct |
2 | Correct | 22 ms | 45948 KB | Output is correct |
3 | Correct | 22 ms | 46200 KB | Output is correct |
4 | Correct | 24 ms | 46080 KB | Output is correct |
5 | Correct | 22 ms | 45568 KB | Output is correct |
6 | Correct | 23 ms | 45696 KB | Output is correct |
7 | Correct | 22 ms | 45824 KB | Output is correct |
8 | Correct | 23 ms | 45432 KB | Output is correct |
9 | Correct | 25 ms | 45440 KB | Output is correct |
10 | Correct | 22 ms | 45440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 51064 KB | Output is correct |
2 | Correct | 31 ms | 50048 KB | Output is correct |
3 | Correct | 35 ms | 53372 KB | Output is correct |
4 | Correct | 33 ms | 51704 KB | Output is correct |
5 | Correct | 35 ms | 46720 KB | Output is correct |
6 | Correct | 31 ms | 47608 KB | Output is correct |
7 | Correct | 29 ms | 48640 KB | Output is correct |
8 | Correct | 24 ms | 45688 KB | Output is correct |
9 | Correct | 25 ms | 47352 KB | Output is correct |
10 | Correct | 31 ms | 46592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 57 ms | 62460 KB | Output is correct |
2 | Correct | 53 ms | 57344 KB | Output is correct |
3 | Correct | 58 ms | 69628 KB | Output is correct |
4 | Correct | 54 ms | 60548 KB | Output is correct |
5 | Correct | 69 ms | 50432 KB | Output is correct |
6 | Correct | 58 ms | 56192 KB | Output is correct |
7 | Correct | 50 ms | 54528 KB | Output is correct |
8 | Correct | 28 ms | 46336 KB | Output is correct |
9 | Correct | 28 ms | 46472 KB | Output is correct |
10 | Correct | 57 ms | 49536 KB | Output is correct |
11 | Correct | 57 ms | 57784 KB | Output is correct |
12 | Correct | 30 ms | 48128 KB | Output is correct |