# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
561529 | 2022-05-13T05:02:36 Z | maximath_1 | Palindromes (APIO14_palindrome) | C++11 | 69 ms | 61140 KB |
#include <iostream> #include <vector> using namespace std; #define ll long long const int MX = 3e5 + 5; struct palindromic_tree{ struct node{ int nxt[26], suff_link, len, cnt; vector<int> edges; } tree[MX]; string s; int suff, num; void add_letter(int pos){ int cr = suff; int cr_len = 0; int letter = s[pos] - 'a'; for(;;){ cr_len = tree[cr].len; if(pos - 1 - cr_len >= 0 && s[pos - 1 - cr_len] == s[pos]) break; cr = tree[cr].suff_link; } if(tree[cr].nxt[letter]){ suff = tree[cr].nxt[letter]; tree[suff].cnt ++; return; } suff = num + 1; num ++; tree[num].len = tree[cr].len + 2; tree[num].cnt = 1; tree[cr].nxt[letter] = num; if(tree[num].len == 1){ tree[num].suff_link = 2; tree[2].edges.push_back(num); return; } for(;;){ cr = tree[cr].suff_link; cr_len = tree[cr].len; if(pos - 1 - cr_len >= 0 && s[pos - 1 - cr_len] == s[pos]){ tree[num].suff_link = tree[cr].nxt[letter]; tree[tree[cr].nxt[letter]].edges.push_back(num); break; } } } void init(){ num = 2; suff = 2; tree[1].len = -1; tree[1].suff_link = 1; tree[2].len = 0; tree[2].suff_link = 1; tree[1].edges.push_back(2); } void dfs_cnt(int nw = 1){ for(int nx : tree[nw].edges){ dfs_cnt(nx); tree[nw].cnt += tree[nx].cnt; } } } pt; string s; int main(){ cin.tie(0) -> sync_with_stdio(0); cin >> s; pt.s = s; pt.init(); for(int i = 0; i < s.size(); i ++) pt.add_letter(i); pt.dfs_cnt(); ll ans = 0ll; for(int i = 0; i < MX; i ++) ans = max(ans, pt.tree[i].len * 1ll * pt.tree[i].cnt); cout << ans << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 42580 KB | Output is correct |
2 | Correct | 20 ms | 42584 KB | Output is correct |
3 | Correct | 19 ms | 42580 KB | Output is correct |
4 | Correct | 19 ms | 42504 KB | Output is correct |
5 | Correct | 18 ms | 42596 KB | Output is correct |
6 | Correct | 19 ms | 42600 KB | Output is correct |
7 | Correct | 20 ms | 42564 KB | Output is correct |
8 | Correct | 20 ms | 42596 KB | Output is correct |
9 | Correct | 19 ms | 42580 KB | Output is correct |
10 | Correct | 20 ms | 42500 KB | Output is correct |
11 | Correct | 20 ms | 42580 KB | Output is correct |
12 | Correct | 22 ms | 42516 KB | Output is correct |
13 | Correct | 22 ms | 42488 KB | Output is correct |
14 | Correct | 24 ms | 42472 KB | Output is correct |
15 | Correct | 20 ms | 42596 KB | Output is correct |
16 | Correct | 20 ms | 42480 KB | Output is correct |
17 | Correct | 21 ms | 42516 KB | Output is correct |
18 | Correct | 20 ms | 42580 KB | Output is correct |
19 | Correct | 20 ms | 42508 KB | Output is correct |
20 | Correct | 21 ms | 42560 KB | Output is correct |
21 | Correct | 22 ms | 42692 KB | Output is correct |
22 | Correct | 22 ms | 42592 KB | Output is correct |
23 | Correct | 21 ms | 42512 KB | Output is correct |
24 | Correct | 21 ms | 42596 KB | Output is correct |
25 | Correct | 20 ms | 42544 KB | Output is correct |
26 | Correct | 21 ms | 42580 KB | Output is correct |
27 | Correct | 20 ms | 42588 KB | Output is correct |
28 | Correct | 21 ms | 42488 KB | Output is correct |
29 | Correct | 23 ms | 42592 KB | Output is correct |
30 | Correct | 22 ms | 42596 KB | Output is correct |
31 | Correct | 21 ms | 42596 KB | Output is correct |
32 | Correct | 21 ms | 42576 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 42580 KB | Output is correct |
2 | Correct | 19 ms | 42580 KB | Output is correct |
3 | Correct | 20 ms | 42580 KB | Output is correct |
4 | Correct | 24 ms | 42604 KB | Output is correct |
5 | Correct | 20 ms | 42636 KB | Output is correct |
6 | Correct | 20 ms | 42580 KB | Output is correct |
7 | Correct | 22 ms | 42584 KB | Output is correct |
8 | Correct | 20 ms | 42536 KB | Output is correct |
9 | Correct | 23 ms | 42580 KB | Output is correct |
10 | Correct | 19 ms | 42516 KB | Output is correct |
11 | Correct | 20 ms | 42580 KB | Output is correct |
12 | Correct | 20 ms | 42592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 42988 KB | Output is correct |
2 | Correct | 21 ms | 42904 KB | Output is correct |
3 | Correct | 20 ms | 43152 KB | Output is correct |
4 | Correct | 24 ms | 43080 KB | Output is correct |
5 | Correct | 23 ms | 42708 KB | Output is correct |
6 | Correct | 22 ms | 42696 KB | Output is correct |
7 | Correct | 21 ms | 42944 KB | Output is correct |
8 | Correct | 20 ms | 42552 KB | Output is correct |
9 | Correct | 21 ms | 42584 KB | Output is correct |
10 | Correct | 21 ms | 42600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 47316 KB | Output is correct |
2 | Correct | 28 ms | 46804 KB | Output is correct |
3 | Correct | 28 ms | 48764 KB | Output is correct |
4 | Correct | 29 ms | 47792 KB | Output is correct |
5 | Correct | 29 ms | 43948 KB | Output is correct |
6 | Correct | 29 ms | 44492 KB | Output is correct |
7 | Correct | 27 ms | 45524 KB | Output is correct |
8 | Correct | 22 ms | 42916 KB | Output is correct |
9 | Correct | 23 ms | 44136 KB | Output is correct |
10 | Correct | 26 ms | 43732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 57060 KB | Output is correct |
2 | Correct | 46 ms | 53992 KB | Output is correct |
3 | Correct | 50 ms | 61140 KB | Output is correct |
4 | Correct | 54 ms | 55828 KB | Output is correct |
5 | Correct | 69 ms | 47976 KB | Output is correct |
6 | Correct | 44 ms | 52188 KB | Output is correct |
7 | Correct | 42 ms | 51284 KB | Output is correct |
8 | Correct | 26 ms | 43604 KB | Output is correct |
9 | Correct | 24 ms | 43512 KB | Output is correct |
10 | Correct | 51 ms | 46956 KB | Output is correct |
11 | Correct | 48 ms | 54176 KB | Output is correct |
12 | Correct | 27 ms | 45032 KB | Output is correct |