Submission #21913

# Submission time Handle Problem Language Result Execution time Memory
21913 2017-04-27T05:25:39 Z Yousef_Salama Palindromes (APIO14_palindrome) C++14
100 / 100
96 ms 67804 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 300005;

char s[MAXN];
int N;

int suflink[MAXN], g[MAXN][26], length[MAXN], flag[MAXN], M, p;
vector <int> G[MAXN];

void init(){
	memset(suflink, -1, sizeof suflink);
	memset(g, -1, sizeof g);

	length[0] = -1;
	length[1] = 0;

	suflink[1] = 0;
	G[0].push_back(1);

	M = 2;
	p = 1;
}

void extend(int i){
	while((i - length[p] - 1 < 0) || (s[i] != s[i - length[p] - 1]))
		p = suflink[p];

	if(g[p][s[i] - 'a'] != -1){
		flag[g[p][s[i] - 'a']]++;
		p = g[p][s[i] - 'a'];
	}else{
		int q = M++;
		g[p][s[i] - 'a'] = q;

		length[q] = length[p] + 2;

		while(true){
			if(p == 0){
				suflink[q] = 1;
				break;
			}

			p = suflink[p];
			if((i - length[p] - 1 >= 0) && (s[i] == s[i - length[p] - 1])){
				suflink[q] = g[p][s[i] - 'a'];
				break;
			}
		}

		G[suflink[q]].push_back(q);

		flag[q]++;
		p = q;
	}
}

int occ[MAXN];
long long solve(int i){
	occ[i] = flag[i];
	long long r = 0;

	for(int j : G[i]){
		r = max(r, solve(j));
		occ[i] += occ[j];
	}
    r = max(r, (long long)occ[i] * length[i]);
    
	return r;
}
int main(){
	scanf("%s", s);
	N = strlen(s);

	init();
	for(int i = 0; i < N; i++)
		extend(i);
		
	printf("%lld\n", solve(0));

	return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:73:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s);
                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 44500 KB Output is correct
2 Correct 6 ms 44500 KB Output is correct
3 Correct 6 ms 44500 KB Output is correct
4 Correct 3 ms 44500 KB Output is correct
5 Correct 6 ms 44500 KB Output is correct
6 Correct 3 ms 44500 KB Output is correct
7 Correct 3 ms 44500 KB Output is correct
8 Correct 3 ms 44500 KB Output is correct
9 Correct 9 ms 44500 KB Output is correct
10 Correct 3 ms 44500 KB Output is correct
11 Correct 3 ms 44500 KB Output is correct
12 Correct 3 ms 44500 KB Output is correct
13 Correct 9 ms 44500 KB Output is correct
14 Correct 3 ms 44500 KB Output is correct
15 Correct 6 ms 44500 KB Output is correct
16 Correct 6 ms 44500 KB Output is correct
17 Correct 13 ms 44500 KB Output is correct
18 Correct 3 ms 44500 KB Output is correct
19 Correct 3 ms 44500 KB Output is correct
20 Correct 6 ms 44500 KB Output is correct
21 Correct 6 ms 44500 KB Output is correct
22 Correct 0 ms 44500 KB Output is correct
23 Correct 3 ms 44500 KB Output is correct
24 Correct 0 ms 44500 KB Output is correct
25 Correct 3 ms 44500 KB Output is correct
26 Correct 3 ms 44500 KB Output is correct
27 Correct 9 ms 44500 KB Output is correct
28 Correct 3 ms 44500 KB Output is correct
29 Correct 9 ms 44500 KB Output is correct
30 Correct 13 ms 44500 KB Output is correct
31 Correct 3 ms 44500 KB Output is correct
32 Correct 0 ms 44500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 44500 KB Output is correct
2 Correct 6 ms 44500 KB Output is correct
3 Correct 3 ms 44500 KB Output is correct
4 Correct 3 ms 44500 KB Output is correct
5 Correct 13 ms 44500 KB Output is correct
6 Correct 0 ms 44500 KB Output is correct
7 Correct 3 ms 44500 KB Output is correct
8 Correct 9 ms 44500 KB Output is correct
9 Correct 0 ms 44500 KB Output is correct
10 Correct 0 ms 44500 KB Output is correct
11 Correct 9 ms 44500 KB Output is correct
12 Correct 3 ms 44500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 44868 KB Output is correct
2 Correct 0 ms 44804 KB Output is correct
3 Correct 6 ms 45108 KB Output is correct
4 Correct 3 ms 45040 KB Output is correct
5 Correct 6 ms 44632 KB Output is correct
6 Correct 9 ms 44632 KB Output is correct
7 Correct 16 ms 44764 KB Output is correct
8 Correct 6 ms 44500 KB Output is correct
9 Correct 0 ms 44500 KB Output is correct
10 Correct 3 ms 44632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 49884 KB Output is correct
2 Correct 3 ms 48860 KB Output is correct
3 Correct 13 ms 52228 KB Output is correct
4 Correct 13 ms 50532 KB Output is correct
5 Correct 19 ms 45688 KB Output is correct
6 Correct 9 ms 46284 KB Output is correct
7 Correct 16 ms 47472 KB Output is correct
8 Correct 6 ms 44500 KB Output is correct
9 Correct 3 ms 46080 KB Output is correct
10 Correct 23 ms 45424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 60776 KB Output is correct
2 Correct 46 ms 55728 KB Output is correct
3 Correct 33 ms 67804 KB Output is correct
4 Correct 39 ms 58844 KB Output is correct
5 Correct 96 ms 48856 KB Output is correct
6 Correct 36 ms 54500 KB Output is correct
7 Correct 36 ms 52872 KB Output is correct
8 Correct 6 ms 44500 KB Output is correct
9 Correct 6 ms 44500 KB Output is correct
10 Correct 76 ms 48064 KB Output is correct
11 Correct 59 ms 56088 KB Output is correct
12 Correct 13 ms 46576 KB Output is correct