# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222227 | 2020-04-12T12:15:46 Z | Bruteforceman | Palindromes (APIO14_palindrome) | C++11 | 92 ms | 66680 KB |
#include <bits/stdc++.h> using namespace std; char s[300010]; int n; struct data { int link, len, cnt; int nxt[26]; data () { link = len = cnt = 0; memset(nxt, 0, sizeof nxt); } } a[300010]; int last; int node; vector <int> g[300010]; int sub[300010]; long long opt; void dfs(int x) { sub[x] = a[x].cnt; for(auto i : g[x]) { dfs(i); sub[x] += sub[i]; } opt = max(opt, 1LL * sub[x] * a[x].len); } void addChar(int idx) { int c = s[idx] - 'a'; int cur = last; while(true) { int len = a[cur].len; if(idx - len - 1 >= 0 && s[idx - len - 1] == s[idx]) { break; } cur = a[cur].link; } if(a[cur].nxt[c] != 0) { last = a[cur].nxt[c]; a[last].cnt += 1; return ; } last = ++node; a[node].len = a[cur].len + 2; a[cur].nxt[c] = node; a[node].cnt += 1; if(a[node].len == 1) { a[node].link = 2; return ; } while(true) { cur = a[cur].link; int len = a[cur].len; if(idx - len - 1 >= 0 && s[idx - len - 1] == s[idx]) { a[node].link = a[cur].nxt[c]; break; } } return ; } void initTree() { node = 2; last = 2; a[1].len = -1; a[2].len = 0; a[1].link = 1; a[2].link = 1; } int main() { scanf("%s", s); n = strlen(s); initTree(); for(int i = 0; i < n; i++) { addChar(i); } for(int i = 2; i <= node; i++) { g[a[i].link].push_back(i); } dfs(1); printf("%lld\n", opt); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 41464 KB | Output is correct |
2 | Correct | 28 ms | 41472 KB | Output is correct |
3 | Correct | 35 ms | 41464 KB | Output is correct |
4 | Correct | 29 ms | 41472 KB | Output is correct |
5 | Correct | 30 ms | 41464 KB | Output is correct |
6 | Correct | 29 ms | 41472 KB | Output is correct |
7 | Correct | 28 ms | 41472 KB | Output is correct |
8 | Correct | 28 ms | 41472 KB | Output is correct |
9 | Correct | 28 ms | 41464 KB | Output is correct |
10 | Correct | 33 ms | 41528 KB | Output is correct |
11 | Correct | 29 ms | 41472 KB | Output is correct |
12 | Correct | 29 ms | 41464 KB | Output is correct |
13 | Correct | 29 ms | 41472 KB | Output is correct |
14 | Correct | 28 ms | 41472 KB | Output is correct |
15 | Correct | 30 ms | 41472 KB | Output is correct |
16 | Correct | 28 ms | 41472 KB | Output is correct |
17 | Correct | 28 ms | 41472 KB | Output is correct |
18 | Correct | 28 ms | 41472 KB | Output is correct |
19 | Correct | 28 ms | 41392 KB | Output is correct |
20 | Correct | 28 ms | 41464 KB | Output is correct |
21 | Correct | 29 ms | 41472 KB | Output is correct |
22 | Correct | 28 ms | 41464 KB | Output is correct |
23 | Correct | 28 ms | 41472 KB | Output is correct |
24 | Correct | 28 ms | 41472 KB | Output is correct |
25 | Correct | 28 ms | 41472 KB | Output is correct |
26 | Correct | 28 ms | 41472 KB | Output is correct |
27 | Correct | 28 ms | 41472 KB | Output is correct |
28 | Correct | 28 ms | 41472 KB | Output is correct |
29 | Correct | 28 ms | 41472 KB | Output is correct |
30 | Correct | 31 ms | 41472 KB | Output is correct |
31 | Correct | 28 ms | 41472 KB | Output is correct |
32 | Correct | 35 ms | 41472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 41472 KB | Output is correct |
2 | Correct | 28 ms | 41472 KB | Output is correct |
3 | Correct | 28 ms | 41472 KB | Output is correct |
4 | Correct | 28 ms | 41472 KB | Output is correct |
5 | Correct | 28 ms | 41472 KB | Output is correct |
6 | Correct | 28 ms | 41472 KB | Output is correct |
7 | Correct | 29 ms | 41472 KB | Output is correct |
8 | Correct | 29 ms | 41472 KB | Output is correct |
9 | Correct | 29 ms | 41464 KB | Output is correct |
10 | Correct | 28 ms | 41472 KB | Output is correct |
11 | Correct | 28 ms | 41472 KB | Output is correct |
12 | Correct | 28 ms | 41472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 41856 KB | Output is correct |
2 | Correct | 29 ms | 41976 KB | Output is correct |
3 | Correct | 30 ms | 42240 KB | Output is correct |
4 | Correct | 30 ms | 42240 KB | Output is correct |
5 | Correct | 30 ms | 41592 KB | Output is correct |
6 | Correct | 30 ms | 41728 KB | Output is correct |
7 | Correct | 29 ms | 41856 KB | Output is correct |
8 | Correct | 28 ms | 41472 KB | Output is correct |
9 | Correct | 29 ms | 41472 KB | Output is correct |
10 | Correct | 29 ms | 41472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 47480 KB | Output is correct |
2 | Correct | 39 ms | 46456 KB | Output is correct |
3 | Correct | 42 ms | 49784 KB | Output is correct |
4 | Correct | 40 ms | 48128 KB | Output is correct |
5 | Correct | 43 ms | 43264 KB | Output is correct |
6 | Correct | 37 ms | 43768 KB | Output is correct |
7 | Correct | 37 ms | 45048 KB | Output is correct |
8 | Correct | 31 ms | 41600 KB | Output is correct |
9 | Correct | 33 ms | 43512 KB | Output is correct |
10 | Correct | 39 ms | 42872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 59896 KB | Output is correct |
2 | Correct | 62 ms | 54520 KB | Output is correct |
3 | Correct | 68 ms | 66680 KB | Output is correct |
4 | Correct | 64 ms | 57720 KB | Output is correct |
5 | Correct | 92 ms | 47608 KB | Output is correct |
6 | Correct | 68 ms | 53240 KB | Output is correct |
7 | Correct | 59 ms | 51576 KB | Output is correct |
8 | Correct | 35 ms | 41984 KB | Output is correct |
9 | Correct | 35 ms | 41976 KB | Output is correct |
10 | Correct | 77 ms | 46584 KB | Output is correct |
11 | Correct | 64 ms | 54904 KB | Output is correct |
12 | Correct | 39 ms | 44288 KB | Output is correct |