# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
12131 | gs14004 | Min-cost GCD (GA9_mcg) | C++98 | 978 ms | 1196 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 <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long lint;
lint dp[100];
lint a,b,p,q;
bool calc_valid(lint x, lint y){
double t = log10(x)+log10(y);
return t < 18;
}
lint f(lint x, lint y, int step){
if(x == 0 || y == 0) return 0;
if(x >= y){
if(dp[step]) return dp[step];
if(!calc_valid(q,x/y)) return dp[step] = f(y,x%y,step+1) + p;
else return dp[step] = min(f(y,x%y,step+1) + p,f(x%y,y,step+1) + q*(x/y));
}
else{
if(!calc_valid(q,y/x)) return 5e18;
else return f(x,y%x,step+1) + q * (y/x);
}
}
void solve(){
# | 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... |