답안 #173639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173639 2020-01-04T18:53:50 Z Pajaraja 회문 (APIO14_palindrome) C++17
100 / 100
63 ms 36372 KB
#include <bits/stdc++.h>
#define MAXN 300007
using namespace std;
struct node {int nxt[26],l,suf; long long br;};
node tree[MAXN];
int br=2,suff=2;
long long res=0;
string s;
void add(int x)
{
	int cur=suff,curl=0;
	int ch=s[x]-'a';
	while(true)
	{
		curl=tree[cur].l;
		if(x-curl-1>=0 && s[x-curl-1]==s[x]) break;
		cur=tree[cur].suf;
	}
	if(tree[cur].nxt[ch]) 
	{
		suff = tree[cur].nxt[ch];
		tree[suff].br++;
		return;
	}
	br++;
	suff=br;
	tree[br].l=tree[cur].l+2;
	tree[cur].nxt[ch]=br;
	tree[br].br=1;
	for(int i=0;i<26;i++) tree[br].nxt[i]=0;
	if(tree[br].l==1) 
	{
		tree[br].suf=2;
		return;
	}
	while(true)
	{
		cur=tree[cur].suf;
		curl=tree[cur].l;
		if(x-curl-1>=0 && s[x-curl-1]==s[x]) break;
	}
	tree[br].suf=tree[cur].nxt[ch];
}
int main()
{
	int n;
	cin>>s; n=s.size();
	tree[1].l=-1; tree[1].suf=1; for(int i=0;i<26;i++) tree[1].nxt[i]=0;
	tree[2].l=0; tree[2].suf=1; for(int i=0;i<26;i++) tree[2].nxt[i]=0;
	for(int i=0;i<s.size();i++) add(i);
	for(int i=br;i>0;i--)
	{
		res=max(res,tree[i].br*tree[i].l);
		tree[tree[i].suf].br+=tree[i].br;
	}
	cout<<res;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++) add(i);
              ~^~~~~~~~~
palindrome.cpp:46:6: warning: variable 'n' set but not used [-Wunused-but-set-variable]
  int n;
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 400 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1532 KB Output is correct
2 Correct 4 ms 1528 KB Output is correct
3 Correct 4 ms 1528 KB Output is correct
4 Correct 4 ms 1528 KB Output is correct
5 Correct 4 ms 1528 KB Output is correct
6 Correct 4 ms 1532 KB Output is correct
7 Correct 4 ms 1528 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12408 KB Output is correct
2 Correct 20 ms 12408 KB Output is correct
3 Correct 19 ms 12408 KB Output is correct
4 Correct 20 ms 12408 KB Output is correct
5 Correct 19 ms 12408 KB Output is correct
6 Correct 17 ms 9128 KB Output is correct
7 Correct 19 ms 10616 KB Output is correct
8 Correct 10 ms 760 KB Output is correct
9 Correct 12 ms 3448 KB Output is correct
10 Correct 18 ms 10504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 36280 KB Output is correct
2 Correct 59 ms 36244 KB Output is correct
3 Correct 56 ms 36244 KB Output is correct
4 Correct 63 ms 36372 KB Output is correct
5 Correct 60 ms 36244 KB Output is correct
6 Correct 55 ms 32276 KB Output is correct
7 Correct 53 ms 30276 KB Output is correct
8 Correct 24 ms 1172 KB Output is correct
9 Correct 25 ms 1168 KB Output is correct
10 Correct 53 ms 29844 KB Output is correct
11 Correct 57 ms 36244 KB Output is correct
12 Correct 27 ms 4372 KB Output is correct