이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stack>
#include <memory.h>
#include <assert.h>
#include <stdlib.h>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
using namespace std;
// for subtask3
long long p,q;
long long Table[2005][2005];
int solve (int a, int b) {
if(a * b == 0) return 0;
if(Table[a][b] >= 0) return Table[a][b];
return Table[a][b] = min (
solve(b, a%b) + p,
(a > b ? solve(a-b, b) : solve(a, b-a)) + q
);
}
int main() {
int t; scanf("%d", &t);
memset(Table, -1, sizeof Table);
while(t--) {
int a,b;
scanf("%d%d%lld%lld", &a, &b, &p, &q);
printf("%d\n", solve(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... |