Submission #27207

#TimeUsernameProblemLanguageResultExecution timeMemory
27207TAMREFMin-cost GCD (GA9_mcg)C++11
30 / 100
256 ms2024 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx=300; ll x,y,p,q; ll eu[mx], dp[2*mx]; int E; void workgcd(ll u, ll v){ eu[E++]=v; if(!v) return; workgcd(v,u%v); } int main(){ int T; for(scanf("%d",&T);T--;){ scanf("%lld%lld%lld%lld",&x,&y,&p,&q); E=0; fill(dp,dp+2*mx,0); eu[E++]=max(x,y); workgcd(max(x,y),min(x,y)); for(int i=E-3;i>=0;i--){ dp[2*i]=min(dp[2*i+2]+p,dp[2*i+3]+q*(eu[i]/eu[i+1])); dp[2*i+1]=min(dp[2*i+2]+q*(eu[i]/eu[i+1]),dp[2*i]+p); } printf("%lld\n",x>=y?dp[0]:dp[1]); } }

Compilation message (stderr)

mcg.cpp: In function 'int main()':
mcg.cpp:15:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d",&T);T--;){
                       ^
mcg.cpp:16:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld%lld",&x,&y,&p,&q);
                                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...