# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
12786 | Qwaz | Min-cost GCD (GA9_mcg) | C++98 | 621 ms | 1084 KiB |
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 <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX = 200;
const ll INF = 5123456789012345678LL;
int maxLevel;
ll p, q, memo[MAX][2];
ll minGcd(ll a, ll b, int level){
if(a == 0 || b == 0) return 0;
ll &now = a >= b ? memo[level][0] : memo[level][1];
maxLevel = max(maxLevel, level);
if(now != 0) return now;
if(a >= b){
now = minGcd(b, a%b, level+1)+p;
ll count = (a - (a%b))/b;
if((INF - minGcd(a%b, b, level+1))/count > q)
now = min(now, minGcd(a%b, b, level+1) + q*count);
} else {
now = minGcd(b, a, level)+p;
ll count = (b - (b%a))/a;
# | 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... |