Submission #47991

# Submission time Handle Problem Language Result Execution time Memory
47991 2018-05-09T10:32:34 Z Kmcode Palindromes (APIO14_palindrome) C++14
0 / 100
26 ms 31648 KB
#include "bits/stdc++.h"
using namespace std;

#define MAX 300015
char buf[MAX];
string s;

int len[MAX];
int linkk[MAX];
int nex[MAX][26];

int ord;
int cur;

int cnt[MAX];

void append(int idx) {
	char c = s[idx];
	while (!(idx-len[cur]-1>=0&&s[idx]==s[idx-len[cur]-1])) {
		cur = linkk[cur];
	}
	if (nex[cur][c - 'a'] == -1) {
		nex[cur][c - 'a'] = ord;
		ord++;
		len[nex[cur][c - 'a']] = len[cur] + 2;
		linkk[nex[cur][c - 'a']] = linkk[cur];
		cur = nex[cur][c - 'a'];
		if (len[cur] == 1) {
			linkk[cur] = 1;
		}
		else {
			while (nex[linkk[cur]][c - 'a'] == -1) {
				linkk[cur] = linkk[linkk[cur]];
			}
			if (linkk[cur] <= 0)exit(1);
			linkk[cur] = nex[linkk[cur]][c - 'a'];
		}
	}
	else {
		cur = nex[cur][c - 'a'];
	}
	cnt[cur]++;
}

int main() {
	memset(nex, -1,sizeof(nex) );
	len[0] = -1;
	len[1] = 0;
	ord = 2;
	scanf("%s", buf);
	s = buf;
	linkk[1] = 0;
	linkk[0] = -1;
	for (int i = 0; i < s.size(); i++) {
		append(i);
	}
	long long int ans = 0;
	for (int i = ord - 1; i >= 2; i--) {
		cnt[linkk[i]] += cnt[i];
		ans = max(ans, (long long int)(len[i])*cnt[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size(); i++) {
                  ~~^~~~~~~~~~
palindrome.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", buf);
  ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 30840 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 30840 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 31004 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 31188 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 31648 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -