답안 #27208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27208 2017-07-10T15:42:22 Z TAMREF Min-cost GCD (GA9_mcg) C++11
57 / 100
286 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);
        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

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);
                                              ^
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 2024 KB Output is correct
2 Correct 119 ms 2024 KB Output is correct
3 Correct 123 ms 2024 KB Output is correct
4 Correct 126 ms 2024 KB Output is correct
5 Correct 113 ms 2024 KB Output is correct
6 Correct 116 ms 2024 KB Output is correct
7 Correct 113 ms 2024 KB Output is correct
8 Correct 119 ms 2024 KB Output is correct
9 Correct 109 ms 2024 KB Output is correct
10 Correct 113 ms 2024 KB Output is correct
11 Correct 113 ms 2024 KB Output is correct
12 Correct 116 ms 2024 KB Output is correct
13 Correct 126 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 116 ms 2024 KB Output is correct
19 Correct 129 ms 2024 KB Output is correct
20 Correct 109 ms 2024 KB Output is correct
21 Correct 113 ms 2024 KB Output is correct
22 Correct 123 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 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 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 3 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 3 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 0 ms 2024 KB Output is correct
27 Correct 0 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 3 ms 2024 KB Output is correct
31 Correct 3 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 2024 KB Output is correct
2 Correct 286 ms 2024 KB Output is correct
3 Correct 243 ms 2024 KB Output is correct
4 Correct 243 ms 2024 KB Output is correct
5 Correct 279 ms 2024 KB Output is correct
6 Correct 259 ms 2024 KB Output is correct
7 Correct 219 ms 2024 KB Output is correct
8 Correct 239 ms 2024 KB Output is correct
9 Correct 236 ms 2024 KB Output is correct
10 Correct 243 ms 2024 KB Output is correct
11 Correct 216 ms 2024 KB Output is correct
12 Correct 279 ms 2024 KB Output is correct
13 Correct 273 ms 2024 KB Output is correct
14 Correct 279 ms 2024 KB Output is correct
15 Correct 279 ms 2024 KB Output is correct
16 Correct 276 ms 2024 KB Output is correct
17 Correct 229 ms 2024 KB Output is correct
18 Correct 259 ms 2024 KB Output is correct
19 Incorrect 169 ms 2024 KB Output isn't correct
20 Halted 0 ms 0 KB -