Submission #12689

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
126892014-12-30 07:33:46gs14004Min-cost GCD (GA9_mcg)C++98
100 / 100
528 ms1084 KiB
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long lint;
lint dp[100], dp2[100];
lint pow[19] = {1,0};
lint a,b,p,q;
inline bool calc_valid(lint x, lint y){
int t = lower_bound(pow,pow+19,x) - pow + lower_bound(pow,pow+19,y) - pow;
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(~dp2[step]) return dp2[step];
if(!calc_valid(q,y/x)) return 5e18;
else return dp2[step] = f(x,y%x,step+1) + q * (y/x);
}
}
void solve(){
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...