Submission #734377

# Submission time Handle Problem Language Result Execution time Memory
734377 2023-05-02T10:47:10 Z SanguineChameleon Palindromes (APIO14_palindrome) C++17
100 / 100
121 ms 105044 KB
#include <bits/stdc++.h>
using namespace std;

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

struct node {
	int len = 0;
	node *ch[26] = {};
	node *suf = nullptr;
	vector<node*> ch_suf;
	int cnt = 0;

	node() {};

	node(int _len): len(_len) {};
};

node *root0 = new node(0);
node *root1 = new node(-1);
const int maxn = 3e5 + 20;
int a[maxn];
long long res;

void dfs(node *u) {
	for (auto v: u->ch_suf) {
		dfs(v);
		u->cnt += v->cnt;
	}
	res = max(res, 1LL * u->len * u->cnt);
}

void just_do_it() {
	root0->suf = root1;
	root1->suf = root1;
	root1->ch_suf.push_back(root0);
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 1; i <= n; i++) {
		a[i] = s[i - 1] - 'a';
	}
	a[0] = -1;
	node *cur = root0;
	for (int i = 1; i <= n; i++) {
		while (a[i - cur->len - 1] != a[i]) {
			cur = cur->suf;
		}
		if (!cur->ch[a[i]]) {
			cur->ch[a[i]] = new node(cur->len + 2);
			if (cur == root1) {
				cur->ch[a[i]]->suf = root0;
			}
			else {
				node *cur_suf = cur->suf;
				while (a[i - cur_suf->len - 1] != a[i]) {
					cur_suf = cur_suf->suf;
				}
				cur->ch[a[i]]->suf = cur_suf->ch[a[i]];
			}
			cur->ch[a[i]]->suf->ch_suf.push_back(cur->ch[a[i]]);
		}
		cur = cur->ch[a[i]];
		cur->cnt++;
	}
	dfs(root1);
	cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 0 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3592 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 3 ms 3796 KB Output is correct
4 Correct 3 ms 3668 KB Output is correct
5 Correct 3 ms 3156 KB Output is correct
6 Correct 4 ms 3272 KB Output is correct
7 Correct 4 ms 3412 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 32852 KB Output is correct
2 Correct 32 ms 31800 KB Output is correct
3 Correct 25 ms 35216 KB Output is correct
4 Correct 25 ms 33528 KB Output is correct
5 Correct 31 ms 29024 KB Output is correct
6 Correct 27 ms 22284 KB Output is correct
7 Correct 26 ms 26452 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 7 ms 8788 KB Output is correct
10 Correct 24 ms 24888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 98016 KB Output is correct
2 Correct 85 ms 92880 KB Output is correct
3 Correct 90 ms 105044 KB Output is correct
4 Correct 78 ms 96316 KB Output is correct
5 Correct 94 ms 87448 KB Output is correct
6 Correct 81 ms 83420 KB Output is correct
7 Correct 67 ms 77060 KB Output is correct
8 Correct 16 ms 2396 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 64 ms 71632 KB Output is correct
11 Correct 121 ms 93672 KB Output is correct
12 Correct 49 ms 11832 KB Output is correct