Submission #12150

# Submission time Handle Problem Language Result Execution time Memory
12150 2014-12-21T10:54:57 Z gs13105 Min-cost GCD (GA9_mcg) C++
30 / 100
108 ms 16724 KB
#include <stdio.h>

int mem[2001][2001];

inline int mn(int a,int b)
{
	return a<b?a:b;
}

int main()
{
	int a,b,p,q,m,t,i,j,k;
	scanf("%d",&t);
	if(t>100)
	{
		scanf("%d%d%d%d",&a,&b,&p,&q);
		for(j=1;j<=2000;j++)
			for(i=1;i<=2000;i++)
				mem[i][j]=mn(p+mem[j][i%j],q+(i>=j?mem[i-j][j]:mem[i][j-i]));
		printf("%d\n",mem[a][b]);
		for(i=0;i<t-1;i++)
		{
			scanf("%d%d%*d%*d",&a,&b);
			printf("%d\n",mem[a][b]);
		}
		return 0;
	}
	for(k=0;k<t;k++)
	{
		scanf("%d%d%d%d",&a,&b,&p,&q);
		m=a>b?a:b;
		for(j=1;j<=m;j++)
			for(i=1;i<=m;i++)
				mem[i][j]=mn(p+mem[j][i%j],q+(i>=j?mem[i-j][j]:mem[i][j-i]));
		printf("%d\n",mem[a][b]);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16724 KB Output is correct
2 Correct 4 ms 16724 KB Output is correct
3 Correct 2 ms 16724 KB Output is correct
4 Correct 4 ms 16724 KB Output is correct
5 Correct 4 ms 16724 KB Output is correct
6 Correct 2 ms 16724 KB Output is correct
7 Correct 5 ms 16724 KB Output is correct
8 Correct 4 ms 16724 KB Output is correct
9 Correct 4 ms 16724 KB Output is correct
10 Correct 4 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 16724 KB Output is correct
2 Correct 108 ms 16724 KB Output is correct
3 Correct 92 ms 16724 KB Output is correct
4 Correct 86 ms 16724 KB Output is correct
5 Correct 87 ms 16724 KB Output is correct
6 Correct 80 ms 16724 KB Output is correct
7 Correct 90 ms 16724 KB Output is correct
8 Correct 87 ms 16724 KB Output is correct
9 Correct 82 ms 16724 KB Output is correct
10 Correct 89 ms 16724 KB Output is correct
11 Correct 75 ms 16724 KB Output is correct
12 Correct 83 ms 16724 KB Output is correct
13 Correct 82 ms 16724 KB Output is correct
14 Correct 31 ms 16724 KB Output is correct
15 Correct 32 ms 16724 KB Output is correct
16 Correct 27 ms 16724 KB Output is correct
17 Correct 28 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 16720 KB Program hung waiting for input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 16720 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -