Submission #13393

# Submission time Handle Problem Language Result Execution time Memory
13393 2015-02-15T18:14:58 Z ggoh 케이크 (JOI13_cake) C++
0 / 100
0 ms 32408 KB
#include<cstdio>
long long a,t,m,i,z[2002],D[2002][2002];
long long max(long long A,long long B)
{
	return A>B?A:B;
}
long long mod(long long X)
{
	return (X+a)%a;
}
long long f(long long x,long long y,long long cnt)
{
	if(cnt==0)return 0;
	if(D[x][y])return D[x][y];
	if((a-cnt)%2==1)
	{
		if(z[x]>z[y])return D[x][y]=f(mod(x-1),y,cnt-1);
		else return D[x][y]=f(x,mod(y+1),cnt-1);
	}
	else
	{
		return D[x][y]=max(z[x]+f(mod(x-1),y,cnt-1),z[y]+f(x,mod(y+1),cnt-1));
	}
}
main()
{
	scanf("%lld",&a);
	for(i=0;i<a;i++)
	{
		scanf("%lld",&z[i]);
	}
	for(i=0;i<a;i++)
	{
		t=z[i]+f(mod(i-1),mod(i+1),a-1);
		printf("%lld ",t);
	}
	
}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 32408 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -