답안 #235871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235871 2020-05-30T08:34:31 Z balbit 회문 (APIO14_palindrome) C++14
23 / 100
1000 ms 82424 KB
#include <stdio.h>
#include <map>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define v 2
ll hhh[10005];
bool ispalindrome[10005][10005];
ll mod_inverse[10005];
char str[10005];
ll modpow(ll x,ll n)
{
	ll res=1;
	while(n)
	{
		if(n&1) res = res*x%mod;
		x = x*x%mod;
		n >>= 1;
	}
	return res;
}
ll calc(int l,int r)
{
	if(l==1) return hhh[r];
	ll d = (hhh[r]-hhh[l-1]+mod)%mod;
	return d*mod_inverse[l]%mod;
}
int main()
{
	scanf("%s",str);
	int n=strlen(str);
	for(int i=n;i>=1;i--) str[i] = str[i-1];
	for(int i=1;i<=n;i++) ispalindrome[i][i]=true;
	for(int i=1;i<n;i++) ispalindrome[i][i+1] = str[i]==str[i+1];
	for(int len=3;len<=n;len++)
	{
		for(int i=1;i+len-1<=n;i++)
		{
			ispalindrome[i][i+len-1] = ispalindrome[i+1][i+len-2] & (str[i] == str[i+len-1]);
		}
	}
	ll cur = 1LL;
	for(int i=1;i<=10005;i++)
	{
		mod_inverse[i] = modpow(cur,mod-2); cur=cur*v%mod;
	}
	cur = 1LL;
	for(int i=1;i<=n;i++)
	{
		hhh[i] = (hhh[i-1]+cur*(str[i]-'a')%mod)%mod;
		cur = cur*v%mod;
	}
	int res=0;
	for(int i=1;i<=n;i++)
	{
		map<ll,int>ch; int maxvalue=0;
		for(int j=1;j+i-1<=n;j++)
		{
			if(ispalindrome[j][j+i-1]) maxvalue = max(maxvalue,++ch[calc(j,j+i-1)]);
		}
		res = max(res,maxvalue*i);
	}
	printf("%d%c",res,10);
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str);
  ~~~~~^~~~~~~~~~
palindrome.cpp:48:18: warning: iteration 10004 invokes undefined behavior [-Waggressive-loop-optimizations]
   mod_inverse[i] = modpow(cur,mod-2); cur=cur*v%mod;
   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
palindrome.cpp:46:15: note: within this loop
  for(int i=1;i<=10005;i++)
              ~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 6 ms 796 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 6 ms 768 KB Output is correct
31 Correct 7 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4864 KB Output is correct
2 Correct 10 ms 4864 KB Output is correct
3 Correct 11 ms 4864 KB Output is correct
4 Correct 10 ms 4864 KB Output is correct
5 Correct 12 ms 4864 KB Output is correct
6 Correct 12 ms 4864 KB Output is correct
7 Correct 9 ms 4864 KB Output is correct
8 Correct 10 ms 4864 KB Output is correct
9 Correct 10 ms 4864 KB Output is correct
10 Correct 9 ms 4864 KB Output is correct
11 Correct 10 ms 4864 KB Output is correct
12 Correct 10 ms 4864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1099 ms 81400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 143 ms 82040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 146 ms 82424 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -