# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
989096 | 2024-05-27T14:10:59 Z | mnbvcxz123 | Palindromes (APIO14_palindrome) | C++17 | 45 ms | 74200 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 | 8 ms | 45404 KB | Output is correct |
2 | Correct | 6 ms | 45404 KB | Output is correct |
3 | Correct | 7 ms | 45404 KB | Output is correct |
4 | Correct | 7 ms | 45656 KB | Output is correct |
5 | Correct | 7 ms | 45404 KB | Output is correct |
6 | Correct | 7 ms | 45404 KB | Output is correct |
7 | Correct | 7 ms | 45404 KB | Output is correct |
8 | Correct | 9 ms | 45404 KB | Output is correct |
9 | Correct | 7 ms | 45404 KB | Output is correct |
10 | Correct | 9 ms | 45404 KB | Output is correct |
11 | Correct | 7 ms | 45404 KB | Output is correct |
12 | Correct | 7 ms | 45520 KB | Output is correct |
13 | Correct | 8 ms | 45404 KB | Output is correct |
14 | Correct | 7 ms | 45404 KB | Output is correct |
15 | Correct | 6 ms | 45404 KB | Output is correct |
16 | Correct | 8 ms | 45404 KB | Output is correct |
17 | Correct | 7 ms | 45520 KB | Output is correct |
18 | Correct | 6 ms | 45404 KB | Output is correct |
19 | Correct | 7 ms | 45528 KB | Output is correct |
20 | Correct | 7 ms | 45404 KB | Output is correct |
21 | Correct | 7 ms | 45404 KB | Output is correct |
22 | Correct | 6 ms | 45400 KB | Output is correct |
23 | Correct | 7 ms | 45404 KB | Output is correct |
24 | Correct | 7 ms | 45656 KB | Output is correct |
25 | Correct | 7 ms | 45428 KB | Output is correct |
26 | Correct | 8 ms | 45404 KB | Output is correct |
27 | Correct | 7 ms | 45404 KB | Output is correct |
28 | Correct | 7 ms | 45404 KB | Output is correct |
29 | Correct | 7 ms | 45404 KB | Output is correct |
30 | Correct | 7 ms | 45404 KB | Output is correct |
31 | Correct | 7 ms | 45400 KB | Output is correct |
32 | Correct | 7 ms | 45404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 45400 KB | Output is correct |
2 | Correct | 7 ms | 45400 KB | Output is correct |
3 | Correct | 8 ms | 45400 KB | Output is correct |
4 | Correct | 8 ms | 45404 KB | Output is correct |
5 | Correct | 7 ms | 45608 KB | Output is correct |
6 | Correct | 7 ms | 45400 KB | Output is correct |
7 | Correct | 7 ms | 45404 KB | Output is correct |
8 | Correct | 7 ms | 45404 KB | Output is correct |
9 | Correct | 7 ms | 45404 KB | Output is correct |
10 | Correct | 7 ms | 45404 KB | Output is correct |
11 | Correct | 7 ms | 45408 KB | Output is correct |
12 | Correct | 7 ms | 45404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 46172 KB | Output is correct |
2 | Correct | 8 ms | 45916 KB | Output is correct |
3 | Correct | 9 ms | 46428 KB | Output is correct |
4 | Correct | 8 ms | 46296 KB | Output is correct |
5 | Correct | 8 ms | 45660 KB | Output is correct |
6 | Correct | 7 ms | 45784 KB | Output is correct |
7 | Correct | 8 ms | 45916 KB | Output is correct |
8 | Correct | 8 ms | 45404 KB | Output is correct |
9 | Correct | 8 ms | 45404 KB | Output is correct |
10 | Correct | 8 ms | 45404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 51800 KB | Output is correct |
2 | Correct | 15 ms | 50524 KB | Output is correct |
3 | Correct | 17 ms | 54876 KB | Output is correct |
4 | Correct | 16 ms | 52828 KB | Output is correct |
5 | Correct | 13 ms | 46816 KB | Output is correct |
6 | Correct | 12 ms | 47704 KB | Output is correct |
7 | Correct | 14 ms | 48984 KB | Output is correct |
8 | Correct | 9 ms | 45660 KB | Output is correct |
9 | Correct | 11 ms | 47708 KB | Output is correct |
10 | Correct | 12 ms | 46672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 64740 KB | Output is correct |
2 | Correct | 30 ms | 58072 KB | Output is correct |
3 | Correct | 45 ms | 74200 KB | Output is correct |
4 | Correct | 33 ms | 62180 KB | Output is correct |
5 | Correct | 36 ms | 50404 KB | Output is correct |
6 | Correct | 32 ms | 57304 KB | Output is correct |
7 | Correct | 29 ms | 55000 KB | Output is correct |
8 | Correct | 12 ms | 46308 KB | Output is correct |
9 | Correct | 12 ms | 46308 KB | Output is correct |
10 | Correct | 27 ms | 49636 KB | Output is correct |
11 | Correct | 31 ms | 58392 KB | Output is correct |
12 | Correct | 15 ms | 48612 KB | Output is correct |