답안 #734381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734381 2023-05-02T10:51:09 Z SanguineChameleon 회문 (APIO14_palindrome) C++17
100 / 100
90 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 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 0 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 292 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3540 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 3 ms 3284 KB Output is correct
7 Correct 3 ms 3412 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 32864 KB Output is correct
2 Correct 24 ms 31860 KB Output is correct
3 Correct 25 ms 35148 KB Output is correct
4 Correct 26 ms 33520 KB Output is correct
5 Correct 47 ms 29104 KB Output is correct
6 Correct 20 ms 22228 KB Output is correct
7 Correct 19 ms 26496 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 12 ms 8788 KB Output is correct
10 Correct 21 ms 24796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 97984 KB Output is correct
2 Correct 75 ms 93000 KB Output is correct
3 Correct 72 ms 105044 KB Output is correct
4 Correct 70 ms 96088 KB Output is correct
5 Correct 90 ms 87124 KB Output is correct
6 Correct 87 ms 83028 KB Output is correct
7 Correct 66 ms 76804 KB Output is correct
8 Correct 14 ms 2176 KB Output is correct
9 Correct 4 ms 2168 KB Output is correct
10 Correct 65 ms 71380 KB Output is correct
11 Correct 68 ms 93256 KB Output is correct
12 Correct 12 ms 11556 KB Output is correct