Submission #290394

# Submission time Handle Problem Language Result Execution time Memory
290394 2020-09-03T17:50:03 Z ZwariowanyMarcin Palindromes (APIO14_palindrome) C++17
100 / 100
30 ms 34944 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ss(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl

using ll = long long;

using namespace std;

const int N = 3e5 + 100;
const int A = 26;

int cnt, len[N], link[N], last, nxt[N][A], q[N];

char s[N];

void add(int x) {
	int v = last, c = s[x] - 'a';
	while (s[x] != s[x - len[v] - 1]) v = link[v];
		
	if (!nxt[v][c]) {
		int ja = ++cnt, k = link[v];
		len[ja] = len[v] + 2;
		while (s[x] != s[x - len[k] - 1]) k = link[k];
		link[ja] = nxt[k][c], nxt[v][c] = ja;
	}
	q[nxt[v][c]]++;
	last = nxt[v][c];
}		

int main() {
	len[1] = -1;
	link[0] = link[1] = 1;
	cnt = 1;
	last = 0;
	
	scanf ("%s", s + 1);
	int n = strlen(s + 1);
	for (int i = 1; i <= n; ++i)
		add(i);
		
	ll out = 0;
	for (int i = cnt; 2 <= i; --i) {
		out = max(out, ll(len[i]) * q[i]);
		q[link[i]] += q[i];
	}
	printf ("%lld\n", out);
	
	return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf ("%s", s + 1);
      |  ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 2 ms 1568 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 2 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11904 KB Output is correct
2 Correct 10 ms 11904 KB Output is correct
3 Correct 10 ms 11904 KB Output is correct
4 Correct 10 ms 11904 KB Output is correct
5 Correct 10 ms 11892 KB Output is correct
6 Correct 8 ms 8832 KB Output is correct
7 Correct 9 ms 10112 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 4 ms 3200 KB Output is correct
10 Correct 9 ms 10112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 34936 KB Output is correct
2 Correct 28 ms 34944 KB Output is correct
3 Correct 30 ms 34936 KB Output is correct
4 Correct 29 ms 34936 KB Output is correct
5 Correct 30 ms 34936 KB Output is correct
6 Correct 26 ms 31096 KB Output is correct
7 Correct 25 ms 29184 KB Output is correct
8 Correct 6 ms 1024 KB Output is correct
9 Correct 6 ms 1024 KB Output is correct
10 Correct 25 ms 28800 KB Output is correct
11 Correct 28 ms 34936 KB Output is correct
12 Correct 8 ms 4224 KB Output is correct