This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
for(k=0;k<t;k++)
{
scanf("%d%d%d%d",&a,&b,&p,&q);
if(t>100&&k)
{
printf("%d\n",mem[a][b]);
continue;
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |