| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 199842 | human1234 | Min-cost GCD (GA9_mcg) | C++14 | 162 ms | 8440 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <vector>
using namespace std;
using i128 = __int128;
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll LIMIT = 1e19;
inline ll conv(i128 x) {
if (x > (i128)LIMIT) return LIMIT;
return (ll)x;
}
int main() {
int t;
vpll v;
scanf("%d", &t);
v.resize(300);
while (t--) {
ll a, b, p, q;
scanf("%lld%lld%lld%lld", &a, &b, &p, &q);
if (a > b) {
v[0] = {0, -1};
} else {
ll t = a;
a = b;
b = t;
v[0] = {p, 0};
}
int c = 0;
while (a && b) {
ll k = a / b, r = a % b;
pll past = v[c], next;
if (past.second == -1) {
next = {conv((i128)p), conv((i128)k * (i128)q)};
} else {
ll f, s;
f = min(conv((i128)past.first + (i128)p), conv((i128)past.second + (i128)k * (i128)q));
s = min(conv((i128)past.first + (i128)k * (i128)q), conv((i128)past.second + (i128)p + (i128)k * (i128)q));
next = {f, s};
}
c++;
v[c] = next;
a = b;
b = r;
}
printf("%lld\n", min(v[c].first, v[c].second));
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
