# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27210 | 2017-07-10T16:00:42 Z | TAMREF | Min-cost GCD (GA9_mcg) | C++11 | 326 ms | 2024 KB |
#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--){ if((double)(p+dp[2*i+2]-dp[2*i+3])/q<eu[i]/eu[i+1]) dp[2*i]=dp[2*i+2]+p; else dp[2*i]=dp[2*i+3]+q*(eu[i]/eu[i+1]); if((double)(p+dp[2*i]-dp[2*i+2])/q<eu[i]/eu[i+1]) dp[2*i+1]=dp[2*i]+p; else dp[2*i+1]=dp[2*i+2]+q*(eu[i]/eu[i+1]); } 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 | 103 ms | 2024 KB | Output is correct |
2 | Correct | 129 ms | 2024 KB | Output is correct |
3 | Correct | 116 ms | 2024 KB | Output is correct |
4 | Correct | 119 ms | 2024 KB | Output is correct |
5 | Correct | 99 ms | 2024 KB | Output is correct |
6 | Correct | 116 ms | 2024 KB | Output is correct |
7 | Correct | 139 ms | 2024 KB | Output is correct |
8 | Correct | 103 ms | 2024 KB | Output is correct |
9 | Correct | 126 ms | 2024 KB | Output is correct |
10 | Correct | 109 ms | 2024 KB | Output is correct |
11 | Correct | 129 ms | 2024 KB | Output is correct |
12 | Correct | 109 ms | 2024 KB | Output is correct |
13 | Correct | 133 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 | 129 ms | 2024 KB | Output is correct |
19 | Correct | 146 ms | 2024 KB | Output is correct |
20 | Correct | 126 ms | 2024 KB | Output is correct |
21 | Correct | 126 ms | 2024 KB | Output is correct |
22 | Correct | 139 ms | 2024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 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 | 3 ms | 2024 KB | Output is correct |
8 | Correct | 3 ms | 2024 KB | Output is correct |
9 | Correct | 3 ms | 2024 KB | Output is correct |
10 | Correct | 0 ms | 2024 KB | Output is correct |
11 | Correct | 0 ms | 2024 KB | Output is correct |
12 | Correct | 3 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 | 0 ms | 2024 KB | Output is correct |
21 | Correct | 3 ms | 2024 KB | Output is correct |
22 | Correct | 3 ms | 2024 KB | Output is correct |
23 | Correct | 0 ms | 2024 KB | Output is correct |
24 | Correct | 3 ms | 2024 KB | Output is correct |
25 | Correct | 3 ms | 2024 KB | Output is correct |
26 | Correct | 3 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 | 0 ms | 2024 KB | Output is correct |
30 | Correct | 0 ms | 2024 KB | Output is correct |
31 | Correct | 0 ms | 2024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 316 ms | 2024 KB | Output is correct |
2 | Correct | 283 ms | 2024 KB | Output is correct |
3 | Correct | 326 ms | 2024 KB | Output is correct |
4 | Correct | 313 ms | 2024 KB | Output is correct |
5 | Correct | 286 ms | 2024 KB | Output is correct |
6 | Correct | 263 ms | 2024 KB | Output is correct |
7 | Correct | 289 ms | 2024 KB | Output is correct |
8 | Correct | 283 ms | 2024 KB | Output is correct |
9 | Correct | 299 ms | 2024 KB | Output is correct |
10 | Correct | 296 ms | 2024 KB | Output is correct |
11 | Correct | 303 ms | 2024 KB | Output is correct |
12 | Correct | 313 ms | 2024 KB | Output is correct |
13 | Correct | 293 ms | 2024 KB | Output is correct |
14 | Correct | 299 ms | 2024 KB | Output is correct |
15 | Correct | 273 ms | 2024 KB | Output is correct |
16 | Correct | 279 ms | 2024 KB | Output is correct |
17 | Correct | 316 ms | 2024 KB | Output is correct |
18 | Correct | 256 ms | 2024 KB | Output is correct |
19 | Correct | 143 ms | 2024 KB | Output is correct |
20 | Correct | 206 ms | 2024 KB | Output is correct |
21 | Correct | 163 ms | 2024 KB | Output is correct |
22 | Correct | 206 ms | 2024 KB | Output is correct |
23 | Correct | 216 ms | 2024 KB | Output is correct |
24 | Correct | 179 ms | 2024 KB | Output is correct |
25 | Correct | 233 ms | 2024 KB | Output is correct |
26 | Correct | 179 ms | 2024 KB | Output is correct |
27 | Correct | 199 ms | 2024 KB | Output is correct |
28 | Correct | 289 ms | 2024 KB | Output is correct |
29 | Correct | 303 ms | 2024 KB | Output is correct |
30 | Correct | 283 ms | 2024 KB | Output is correct |
31 | Correct | 323 ms | 2024 KB | Output is correct |
32 | Correct | 299 ms | 2024 KB | Output is correct |
33 | Correct | 309 ms | 2024 KB | Output is correct |
34 | Correct | 293 ms | 2024 KB | Output is correct |
35 | Correct | 306 ms | 2024 KB | Output is correct |