답안 #12206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
12206 2014-12-24T08:44:43 Z qja0950 Min-cost GCD (GA9_mcg) C++
30 / 100
158 ms 1084 KB
//
//  main.cpp
//  2. Min-cost GCD (mcg)
//
//  Created by KJBS2 on 2014. 12. 24..
//  Copyright (c) 2014년 KJBS2. All rights reserved.
//

#include <stdio.h>
#include <algorithm>

using namespace std;

typedef long long ll;

#define MAX_LL ((ll)1*0x7fffffff*0x7fffffff)

ll A, B, P, Q;
ll X, Y, Z, W;
void PROCESS() {
    scanf("%lld%lld%lld%lld", &A, &B, &P, &Q);
    X = 0; Y = MAX_LL;
    for(; A!=0 && B!=0;) {
        ll C = A % B, D = A / B;
        
        Z = X + P;
        W = X + D * Q;
        
        if(Y != MAX_LL) {
            Z = min(Z, Y + P + P);
            Z = min(Z, Y + D * Q);
            W = min(W, Y + P + D * Q);
        }
        X = Z;
        Y = W;
        
        A = B; B = C;
    }
    
    printf("%lld\n", min(X, Y) );
}

int main() {
    int T; scanf("%d", &T);
    for(int i=0; i<T; i++)
        PROCESS();
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Correct 0 ms 1084 KB Output is correct
6 Correct 0 ms 1084 KB Output is correct
7 Correct 0 ms 1084 KB Output is correct
8 Correct 0 ms 1084 KB Output is correct
9 Correct 0 ms 1084 KB Output is correct
10 Correct 0 ms 1084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 1084 KB Output is correct
2 Correct 73 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 65 ms 1084 KB Output is correct
5 Correct 44 ms 1084 KB Output is correct
6 Correct 39 ms 1084 KB Output is correct
7 Correct 63 ms 1084 KB Output is correct
8 Correct 71 ms 1084 KB Output is correct
9 Correct 73 ms 1084 KB Output is correct
10 Correct 68 ms 1084 KB Output is correct
11 Correct 59 ms 1084 KB Output is correct
12 Correct 69 ms 1084 KB Output is correct
13 Correct 64 ms 1084 KB Output is correct
14 Correct 0 ms 1084 KB Output is correct
15 Correct 0 ms 1084 KB Output is correct
16 Correct 0 ms 1084 KB Output is correct
17 Correct 0 ms 1084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1084 KB Output is correct
2 Incorrect 1 ms 1084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 1084 KB Output isn't correct
2 Halted 0 ms 0 KB -