답안 #100231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100231 2019-03-09T21:50:45 Z TadijaSebez 회문 (APIO14_palindrome) C++11
100 / 100
104 ms 59768 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=300050;
struct EERTREE
{
	char s[N];
	int link[N],at,go[N][26],len[N],cnt[N],ZERO,IMAG,tsz,sz;
	vector<int> E[N];
	void init()
	{
		IMAG=++tsz;link[IMAG]=IMAG;len[IMAG]=-1;
		ZERO=++tsz;link[ZERO]=IMAG;len[ZERO]=0;
		E[IMAG].push_back(ZERO);
		at=IMAG;
	}
	EERTREE(){ init();}
	void Grow()
	{
		++sz;
		while(s[sz]!=s[sz-len[at]-1]) at=link[at];
		if(!go[at][s[sz]-'a'])
		{
			tsz++;link[tsz]=link[at];go[at][s[sz]-'a']=tsz;len[tsz]=len[at]+2;
			while(s[sz]!=s[sz-len[link[tsz]]-1]) link[tsz]=link[link[tsz]];
			if(len[tsz]==1) link[tsz]=ZERO;
			else link[tsz]=go[link[tsz]][s[sz]-'a'];
			E[link[tsz]].push_back(tsz);
		}
		at=go[at][s[sz]-'a'];cnt[at]++;
	}
	void DFS(int u)
	{
		for(int v:E[u]) DFS(v),cnt[u]+=cnt[v];
	}
	ll Solve()
	{
		DFS(IMAG);
		ll ans=0;
		for(int i=1;i<=tsz;i++) if(len[i]>0) ans=max(ans,(ll)len[i]*cnt[i]);
		return ans;
	}
} TREE;
int main()
{
	int n;
	scanf("%s",TREE.s+1);
	n=strlen(TREE.s+1);
	for(int i=1;i<=n;i++) TREE.Grow();
	printf("%lld\n",TREE.Solve());
	return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",TREE.s+1);
  ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 7 ms 7424 KB Output is correct
9 Correct 8 ms 7444 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
11 Correct 8 ms 7424 KB Output is correct
12 Correct 7 ms 7424 KB Output is correct
13 Correct 8 ms 7424 KB Output is correct
14 Correct 9 ms 7424 KB Output is correct
15 Correct 10 ms 7424 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 8 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 8 ms 7424 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 10 ms 7344 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 9 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7396 KB Output is correct
26 Correct 8 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 7 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7552 KB Output is correct
2 Correct 8 ms 7552 KB Output is correct
3 Correct 10 ms 7552 KB Output is correct
4 Correct 9 ms 7604 KB Output is correct
5 Correct 7 ms 7552 KB Output is correct
6 Correct 9 ms 7680 KB Output is correct
7 Correct 8 ms 7552 KB Output is correct
8 Correct 8 ms 7552 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
11 Correct 8 ms 7424 KB Output is correct
12 Correct 8 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8960 KB Output is correct
2 Correct 11 ms 8884 KB Output is correct
3 Correct 11 ms 9088 KB Output is correct
4 Correct 10 ms 9088 KB Output is correct
5 Correct 12 ms 8704 KB Output is correct
6 Correct 9 ms 8704 KB Output is correct
7 Correct 10 ms 8832 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 8320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 23424 KB Output is correct
2 Correct 31 ms 22776 KB Output is correct
3 Correct 33 ms 24796 KB Output is correct
4 Correct 29 ms 23800 KB Output is correct
5 Correct 39 ms 20096 KB Output is correct
6 Correct 26 ms 17536 KB Output is correct
7 Correct 28 ms 19960 KB Output is correct
8 Correct 10 ms 7680 KB Output is correct
9 Correct 16 ms 11520 KB Output is correct
10 Correct 27 ms 18176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 55544 KB Output is correct
2 Correct 77 ms 52600 KB Output is correct
3 Correct 100 ms 59768 KB Output is correct
4 Correct 82 ms 54488 KB Output is correct
5 Correct 103 ms 46456 KB Output is correct
6 Correct 70 ms 47236 KB Output is correct
7 Correct 66 ms 44152 KB Output is correct
8 Correct 13 ms 8192 KB Output is correct
9 Correct 14 ms 8192 KB Output is correct
10 Correct 80 ms 39512 KB Output is correct
11 Correct 104 ms 52728 KB Output is correct
12 Correct 21 ms 12792 KB Output is correct