Submission #440220

# Submission time Handle Problem Language Result Execution time Memory
440220 2021-07-01T19:07:11 Z keta_tsimakuridze Palindromes (APIO14_palindrome) C++14
100 / 100
107 ms 90156 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=3e5+5,mod=1e9+7;
int t,in[N],idx,suff;
vector<int>V[N];
string s;
queue<int> q;
struct st{
	int vis[27];
	int sufflink;
	int cnt;
	int len;
} tree[N];
void add(int i){
	int cur = suff;
	while(true) {
		if(s[i - tree[cur].len - 1] == s[i]) {
			if(tree[cur].vis[s[i]-'a']) {
				suff = tree[cur].vis[s[i]-'a']; 
				tree[suff].cnt++; 
				return;
			}
			suff = ++idx; 
			tree[idx].cnt = 1;
			tree[cur].vis[s[i]-'a'] = idx;
			tree[idx].len = tree[cur].len + 2;
			break;
		}
	
		cur = tree[cur].sufflink;
	}
	if(tree[idx].len == 1){
		tree[idx].sufflink = 2;
		return;
	} 

	while(true) { 
		cur = tree[cur].sufflink;
		if(s[i - tree[cur].len - 1] == s[i]) {
			tree[idx].sufflink = tree[cur].vis[s[i]-'a'];
			V[idx].push_back(tree[cur].vis[s[i]-'a']);
			in[tree[cur].vis[s[i]-'a']]++;
			break;
		}
	}
	
}
 main(){
	cin>>s;
	int n = s.size();
	s = '#' + s;
	idx = 2;
	tree[1].len = -1; 
	tree[2].len = 0;
	in[1] +=2;
	tree[1].sufflink = tree[2].sufflink = 1;
	suff = 2;
	for(int i=1;i<=n;i++){
		add(i);
	}
	for(int i=1;i<=idx;i++) {
		if(!in[i]) q.push(i);
	}
	int ans = 0;
	while(q.size()){ 
		int u = q.front();
		q.pop();
		ans = max(ans, tree[u].len * tree[u].cnt);
		for(int i=0;i<V[u].size();i++) {
			in[V[u][i]]--;
			tree[V[u][i]].cnt += tree[u].cnt;
			if(!in[V[u][i]]) q.push(V[u][i]);
		}
	}
	cout<<ans;
}

Compilation message

palindrome.cpp:51:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 |  main(){
      |  ^~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:72:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for(int i=0;i<V[u].size();i++) {
      |               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 6 ms 7352 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7244 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 5 ms 7340 KB Output is correct
13 Correct 5 ms 7244 KB Output is correct
14 Correct 5 ms 7244 KB Output is correct
15 Correct 5 ms 7244 KB Output is correct
16 Correct 5 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 6 ms 7244 KB Output is correct
19 Correct 5 ms 7372 KB Output is correct
20 Correct 5 ms 7372 KB Output is correct
21 Correct 6 ms 7372 KB Output is correct
22 Correct 5 ms 7372 KB Output is correct
23 Correct 5 ms 7380 KB Output is correct
24 Correct 5 ms 7320 KB Output is correct
25 Correct 6 ms 7372 KB Output is correct
26 Correct 5 ms 7372 KB Output is correct
27 Correct 5 ms 7372 KB Output is correct
28 Correct 5 ms 7372 KB Output is correct
29 Correct 5 ms 7244 KB Output is correct
30 Correct 5 ms 7244 KB Output is correct
31 Correct 6 ms 7244 KB Output is correct
32 Correct 5 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7628 KB Output is correct
2 Correct 5 ms 7628 KB Output is correct
3 Correct 6 ms 7628 KB Output is correct
4 Correct 6 ms 7500 KB Output is correct
5 Correct 6 ms 7616 KB Output is correct
6 Correct 6 ms 7628 KB Output is correct
7 Correct 6 ms 7628 KB Output is correct
8 Correct 6 ms 7596 KB Output is correct
9 Correct 6 ms 7500 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 5 ms 7372 KB Output is correct
12 Correct 5 ms 7500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10036 KB Output is correct
2 Correct 8 ms 10068 KB Output is correct
3 Correct 8 ms 10112 KB Output is correct
4 Correct 8 ms 10060 KB Output is correct
5 Correct 8 ms 10060 KB Output is correct
6 Correct 8 ms 10060 KB Output is correct
7 Correct 8 ms 10060 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 8 ms 9164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 34820 KB Output is correct
2 Correct 47 ms 34760 KB Output is correct
3 Correct 35 ms 34796 KB Output is correct
4 Correct 36 ms 34740 KB Output is correct
5 Correct 33 ms 34752 KB Output is correct
6 Correct 31 ms 27336 KB Output is correct
7 Correct 32 ms 30560 KB Output is correct
8 Correct 9 ms 7752 KB Output is correct
9 Correct 15 ms 13736 KB Output is correct
10 Correct 28 ms 30680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 89704 KB Output is correct
2 Correct 107 ms 90044 KB Output is correct
3 Correct 80 ms 90032 KB Output is correct
4 Correct 95 ms 90084 KB Output is correct
5 Correct 99 ms 90156 KB Output is correct
6 Correct 93 ms 80860 KB Output is correct
7 Correct 92 ms 76156 KB Output is correct
8 Correct 18 ms 8536 KB Output is correct
9 Correct 18 ms 8388 KB Output is correct
10 Correct 72 ms 75160 KB Output is correct
11 Correct 89 ms 90120 KB Output is correct
12 Correct 23 ms 15684 KB Output is correct