Submission #748326

# Submission time Handle Problem Language Result Execution time Memory
748326 2023-05-26T06:34:50 Z denniskim Palindromes (APIO14_palindrome) C++17
100 / 100
94 ms 79548 KB
#include <bits/stdc++.h>

using namespace std;
typedef int ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

char a[600010];
ll len;
long long dp[600010];

struct node
{
	ll adj[26] = {0, };
	ll suffixlink = 0;
	ll LEN = 0, COU = 0;
};

struct eertree
{
	vector<node> eer;
	ll pos = 0;
	
	void init(void)
	{
		node tmp;
		
		tmp.suffixlink = 0;
		tmp.LEN = -1;
		tmp.COU = 1;
		
		eer.push_back(tmp);
		
		tmp.suffixlink = 0;
		tmp.LEN = 0;
		tmp.COU = 1;
		
		eer.push_back(tmp);
	}
	
	void add(ll I)
	{
		while(1)
		{
			if(I - eer[pos].LEN - 1 >= 0 && a[I] == a[I - eer[pos].LEN - 1])
				break;
			
			pos = eer[pos].suffixlink;
		}
		
		if(eer[pos].adj[a[I] - 'a'])
		{
			pos = eer[pos].adj[a[I] - 'a'];
			eer[pos].COU++;
			
			return;
		}
		
		node tmp;
		
		eer[pos].adj[a[I] - 'a'] = (ll)eer.size();
		
		tmp.LEN = eer[pos].LEN + 2;
		tmp.COU = 1;
		
		if(tmp.LEN == 1)
			tmp.suffixlink = 1;
		
		else
		{
			pos = eer[pos].suffixlink;
			
			while(1)
			{
				if(I - eer[pos].LEN - 1 >= 0 && a[I] == a[I - eer[pos].LEN - 1])
					break;
				
				pos = eer[pos].suffixlink;
			}
			
			if(!eer[pos].adj[a[I] - 'a'])
				assert(0);
			
			tmp.suffixlink = eer[pos].adj[a[I] - 'a'];
		}
		
		pos = (ll)eer.size();
		eer.push_back(tmp);
	}
}eert;

vector<ll> vec[600010];
ll siz;
long long ans;

void dfs(ll here, ll pa)
{
	for(auto &i : vec[here])
	{
		if(i == pa)
			continue;
		
		dfs(i, here);
		dp[here] += dp[i];
	}
}

int main(void)
{
	fastio
	
	cin >> a;
	
	len = strlen(a);
	eert.init();
	
	for(ll i = 0 ; i < len ; i++)
		eert.add(i);
	
	siz = (ll)eert.eer.size();
	
	for(ll i = 1 ; i < siz ; i++)
		vec[eert.eer[i].suffixlink].push_back(i);
	
	for(ll i = 0 ; i < siz ; i++)
		dp[i] = eert.eer[i].COU;
	
	dfs(0, -1);
	
	for(ll i = 0 ; i < siz ; i++)
		ans = max(ans, (long long)eert.eer[i].LEN * dp[i]);
	
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14404 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
4 Correct 9 ms 14308 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 8 ms 14332 KB Output is correct
9 Correct 7 ms 14376 KB Output is correct
10 Correct 7 ms 14348 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 8 ms 14432 KB Output is correct
13 Correct 9 ms 14324 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 9 ms 14380 KB Output is correct
18 Correct 8 ms 14384 KB Output is correct
19 Correct 10 ms 14420 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 9 ms 14420 KB Output is correct
22 Correct 9 ms 14420 KB Output is correct
23 Correct 8 ms 14368 KB Output is correct
24 Correct 8 ms 14420 KB Output is correct
25 Correct 8 ms 14420 KB Output is correct
26 Correct 8 ms 14420 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 8 ms 14420 KB Output is correct
29 Correct 8 ms 14320 KB Output is correct
30 Correct 8 ms 14420 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 8 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14676 KB Output is correct
2 Correct 8 ms 14604 KB Output is correct
3 Correct 8 ms 14676 KB Output is correct
4 Correct 8 ms 14548 KB Output is correct
5 Correct 9 ms 14676 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 8 ms 14676 KB Output is correct
9 Correct 8 ms 14548 KB Output is correct
10 Correct 8 ms 14444 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 9 ms 14548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16432 KB Output is correct
2 Correct 10 ms 16428 KB Output is correct
3 Correct 10 ms 16520 KB Output is correct
4 Correct 10 ms 16492 KB Output is correct
5 Correct 10 ms 16352 KB Output is correct
6 Correct 10 ms 16416 KB Output is correct
7 Correct 10 ms 16408 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 9 ms 14524 KB Output is correct
10 Correct 9 ms 15612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 32936 KB Output is correct
2 Correct 28 ms 31548 KB Output is correct
3 Correct 30 ms 36028 KB Output is correct
4 Correct 31 ms 33764 KB Output is correct
5 Correct 30 ms 29500 KB Output is correct
6 Correct 25 ms 29472 KB Output is correct
7 Correct 26 ms 29504 KB Output is correct
8 Correct 9 ms 14676 KB Output is correct
9 Correct 15 ms 19396 KB Output is correct
10 Correct 26 ms 29504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 74320 KB Output is correct
2 Correct 75 ms 74616 KB Output is correct
3 Correct 80 ms 79548 KB Output is correct
4 Correct 78 ms 74548 KB Output is correct
5 Correct 94 ms 74680 KB Output is correct
6 Correct 83 ms 74620 KB Output is correct
7 Correct 57 ms 54336 KB Output is correct
8 Correct 13 ms 15324 KB Output is correct
9 Correct 13 ms 15280 KB Output is correct
10 Correct 62 ms 48328 KB Output is correct
11 Correct 80 ms 74576 KB Output is correct
12 Correct 18 ms 21044 KB Output is correct