# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27209 | 2017-07-10T15:53:53 Z | TAMREF | Min-cost GCD (GA9_mcg) | C++11 | 356 ms | 2024 KB |
#include <bits/stdc++.h> using namespace std; typedef unsigned 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); ll g=__gcd(x,y); x/=g, y/=g; 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2024 KB | Output is correct |
2 | Correct | 0 ms | 2024 KB | Output is correct |
3 | Correct | 0 ms | 2024 KB | Output is correct |
4 | Correct | 0 ms | 2024 KB | Output is correct |
5 | Correct | 0 ms | 2024 KB | Output is correct |
6 | Correct | 0 ms | 2024 KB | Output is correct |
7 | Correct | 0 ms | 2024 KB | Output is correct |
8 | Correct | 0 ms | 2024 KB | Output is correct |
9 | Correct | 0 ms | 2024 KB | Output is correct |
10 | Correct | 0 ms | 2024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 2024 KB | Output is correct |
2 | Correct | 126 ms | 2024 KB | Output is correct |
3 | Correct | 119 ms | 2024 KB | Output is correct |
4 | Correct | 123 ms | 2024 KB | Output is correct |
5 | Correct | 136 ms | 2024 KB | Output is correct |
6 | Correct | 116 ms | 2024 KB | Output is correct |
7 | Correct | 126 ms | 2024 KB | Output is correct |
8 | Correct | 126 ms | 2024 KB | Output is correct |
9 | Correct | 116 ms | 2024 KB | Output is correct |
10 | Correct | 119 ms | 2024 KB | Output is correct |
11 | Correct | 123 ms | 2024 KB | Output is correct |
12 | Correct | 123 ms | 2024 KB | Output is correct |
13 | Correct | 136 ms | 2024 KB | Output is correct |
14 | Correct | 0 ms | 2024 KB | Output is correct |
15 | Correct | 0 ms | 2024 KB | Output is correct |
16 | Correct | 0 ms | 2024 KB | Output is correct |
17 | Correct | 0 ms | 2024 KB | Output is correct |
18 | Correct | 149 ms | 2024 KB | Output is correct |
19 | Correct | 129 ms | 2024 KB | Output is correct |
20 | Correct | 143 ms | 2024 KB | Output is correct |
21 | Correct | 129 ms | 2024 KB | Output is correct |
22 | Correct | 149 ms | 2024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2024 KB | Output is correct |
2 | Correct | 0 ms | 2024 KB | Output is correct |
3 | Correct | 0 ms | 2024 KB | Output is correct |
4 | Correct | 3 ms | 2024 KB | Output is correct |
5 | Correct | 3 ms | 2024 KB | Output is correct |
6 | Correct | 0 ms | 2024 KB | Output is correct |
7 | Correct | 0 ms | 2024 KB | Output is correct |
8 | Correct | 0 ms | 2024 KB | Output is correct |
9 | Correct | 0 ms | 2024 KB | Output is correct |
10 | Correct | 0 ms | 2024 KB | Output is correct |
11 | Correct | 3 ms | 2024 KB | Output is correct |
12 | Correct | 0 ms | 2024 KB | Output is correct |
13 | Correct | 0 ms | 2024 KB | Output is correct |
14 | Correct | 0 ms | 2024 KB | Output is correct |
15 | Correct | 0 ms | 2024 KB | Output is correct |
16 | Correct | 0 ms | 2024 KB | Output is correct |
17 | Correct | 0 ms | 2024 KB | Output is correct |
18 | Correct | 0 ms | 2024 KB | Output is correct |
19 | Correct | 0 ms | 2024 KB | Output is correct |
20 | Correct | 3 ms | 2024 KB | Output is correct |
21 | Correct | 0 ms | 2024 KB | Output is correct |
22 | Correct | 3 ms | 2024 KB | Output is correct |
23 | Correct | 3 ms | 2024 KB | Output is correct |
24 | Correct | 3 ms | 2024 KB | Output is correct |
25 | Correct | 0 ms | 2024 KB | Output is correct |
26 | Correct | 0 ms | 2024 KB | Output is correct |
27 | Correct | 3 ms | 2024 KB | Output is correct |
28 | Correct | 0 ms | 2024 KB | Output is correct |
29 | Correct | 3 ms | 2024 KB | Output is correct |
30 | Correct | 0 ms | 2024 KB | Output is correct |
31 | Correct | 3 ms | 2024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 276 ms | 2024 KB | Output is correct |
2 | Correct | 269 ms | 2024 KB | Output is correct |
3 | Correct | 306 ms | 2024 KB | Output is correct |
4 | Correct | 303 ms | 2024 KB | Output is correct |
5 | Correct | 283 ms | 2024 KB | Output is correct |
6 | Correct | 299 ms | 2024 KB | Output is correct |
7 | Correct | 323 ms | 2024 KB | Output is correct |
8 | Correct | 316 ms | 2024 KB | Output is correct |
9 | Correct | 259 ms | 2024 KB | Output is correct |
10 | Correct | 316 ms | 2024 KB | Output is correct |
11 | Correct | 309 ms | 2024 KB | Output is correct |
12 | Correct | 306 ms | 2024 KB | Output is correct |
13 | Correct | 293 ms | 2024 KB | Output is correct |
14 | Correct | 309 ms | 2024 KB | Output is correct |
15 | Correct | 336 ms | 2024 KB | Output is correct |
16 | Correct | 286 ms | 2024 KB | Output is correct |
17 | Correct | 356 ms | 2024 KB | Output is correct |
18 | Correct | 333 ms | 2024 KB | Output is correct |
19 | Incorrect | 163 ms | 2024 KB | Output isn't correct |
20 | Halted | 0 ms | 0 KB | - |