답안 #103339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103339 2019-03-29T18:48:35 Z Minnakhmetov 회문 (APIO14_palindrome) C++14
100 / 100
44 ms 35072 KB
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)

const int N = 3e5 + 5, A = 26;
int to[N][A], link[N], len[N], w[N];
string s;
int n, z = 2, suf;

void addLetter(int p) {
	while (p - len[suf] - 1 < 0 || s[p - len[suf] - 1] != s[p])
		suf = link[suf];

	int c = s[p] - 'a';
	if (to[suf][c] != -1) {
		suf = to[suf][c];
		w[suf]++;
		return;
	}

	
	to[suf][c] = z;
	w[z]++;
	len[z] = len[suf] + 2;

	if (len[z] == 1) {
		link[z] = 0;
	}
	else {
		int v = link[suf];
		while (p - len[v] - 1 < 0 || s[p - len[v] - 1] != s[p])
			v = link[v];

		link[z] = to[v][c];
	}

	suf = z;
	z++;
}

signed main() {
#ifdef HOME
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> s;
	n = s.size();

	memset(to, -1, sizeof(to));

	len[0] = 0;
	len[1] = -1;
	link[0] = 1;
	link[1] = 1;

	suf = 0;

	for (int i = 0; i < n; i++) {
		addLetter(i);
	}

	for (int i = z - 1; i >= 0; i--) {
		w[link[i]] += w[i];
	}

	ll ans = 0;

	for (int i = 0; i < z; i++) {
		ans = max(ans, len[i] * (ll)w[i]);
	}

	cout << ans;

	return 0;
}

Compilation message

palindrome.cpp:41:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 30860 KB Output is correct
2 Correct 25 ms 30976 KB Output is correct
3 Correct 26 ms 30968 KB Output is correct
4 Correct 24 ms 30848 KB Output is correct
5 Correct 24 ms 30848 KB Output is correct
6 Correct 27 ms 30976 KB Output is correct
7 Correct 26 ms 30840 KB Output is correct
8 Correct 32 ms 30844 KB Output is correct
9 Correct 29 ms 30848 KB Output is correct
10 Correct 27 ms 30844 KB Output is correct
11 Correct 27 ms 30848 KB Output is correct
12 Correct 27 ms 30840 KB Output is correct
13 Correct 28 ms 30848 KB Output is correct
14 Correct 26 ms 30848 KB Output is correct
15 Correct 29 ms 30848 KB Output is correct
16 Correct 34 ms 30812 KB Output is correct
17 Correct 25 ms 30848 KB Output is correct
18 Correct 26 ms 30848 KB Output is correct
19 Correct 28 ms 30848 KB Output is correct
20 Correct 26 ms 30848 KB Output is correct
21 Correct 27 ms 30872 KB Output is correct
22 Correct 24 ms 30848 KB Output is correct
23 Correct 24 ms 30968 KB Output is correct
24 Correct 29 ms 30840 KB Output is correct
25 Correct 24 ms 30848 KB Output is correct
26 Correct 28 ms 30848 KB Output is correct
27 Correct 25 ms 30840 KB Output is correct
28 Correct 24 ms 30848 KB Output is correct
29 Correct 28 ms 30840 KB Output is correct
30 Correct 25 ms 30848 KB Output is correct
31 Correct 24 ms 30848 KB Output is correct
32 Correct 29 ms 30848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 30852 KB Output is correct
2 Correct 24 ms 30848 KB Output is correct
3 Correct 25 ms 30968 KB Output is correct
4 Correct 25 ms 30976 KB Output is correct
5 Correct 25 ms 30848 KB Output is correct
6 Correct 25 ms 30976 KB Output is correct
7 Correct 33 ms 30968 KB Output is correct
8 Correct 25 ms 30976 KB Output is correct
9 Correct 24 ms 30968 KB Output is correct
10 Correct 28 ms 30848 KB Output is correct
11 Correct 27 ms 30848 KB Output is correct
12 Correct 27 ms 30968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 31032 KB Output is correct
2 Correct 25 ms 30976 KB Output is correct
3 Correct 24 ms 30976 KB Output is correct
4 Correct 26 ms 31096 KB Output is correct
5 Correct 24 ms 30976 KB Output is correct
6 Correct 26 ms 31104 KB Output is correct
7 Correct 25 ms 31100 KB Output is correct
8 Correct 25 ms 30848 KB Output is correct
9 Correct 24 ms 30976 KB Output is correct
10 Correct 29 ms 31068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 32276 KB Output is correct
2 Correct 30 ms 32248 KB Output is correct
3 Correct 31 ms 32272 KB Output is correct
4 Correct 29 ms 32312 KB Output is correct
5 Correct 29 ms 32252 KB Output is correct
6 Correct 28 ms 31964 KB Output is correct
7 Correct 33 ms 32120 KB Output is correct
8 Correct 29 ms 31104 KB Output is correct
9 Correct 27 ms 31352 KB Output is correct
10 Correct 34 ms 32128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 34816 KB Output is correct
2 Correct 42 ms 34832 KB Output is correct
3 Correct 38 ms 34816 KB Output is correct
4 Correct 40 ms 34916 KB Output is correct
5 Correct 43 ms 34788 KB Output is correct
6 Correct 36 ms 34432 KB Output is correct
7 Correct 37 ms 34176 KB Output is correct
8 Correct 32 ms 31368 KB Output is correct
9 Correct 34 ms 31368 KB Output is correct
10 Correct 43 ms 34304 KB Output is correct
11 Correct 44 ms 35072 KB Output is correct
12 Correct 31 ms 31924 KB Output is correct