답안 #27207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27207 2017-07-10T15:41:14 Z TAMREF Min-cost GCD (GA9_mcg) C++11
30 / 100
256 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--){
            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 99 ms 2024 KB Output is correct
2 Correct 133 ms 2024 KB Output is correct
3 Correct 123 ms 2024 KB Output is correct
4 Correct 116 ms 2024 KB Output is correct
5 Correct 109 ms 2024 KB Output is correct
6 Correct 119 ms 2024 KB Output is correct
7 Correct 129 ms 2024 KB Output is correct
8 Correct 116 ms 2024 KB Output is correct
9 Correct 139 ms 2024 KB Output is correct
10 Correct 123 ms 2024 KB Output is correct
11 Correct 109 ms 2024 KB Output is correct
12 Correct 129 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 126 ms 2024 KB Output is correct
19 Correct 129 ms 2024 KB Output is correct
20 Correct 129 ms 2024 KB Output is correct
21 Correct 99 ms 2024 KB Output is correct
22 Correct 139 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Incorrect 3 ms 2024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 256 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -