답안 #12115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
12115 2014-12-21T07:23:42 Z tncks0121 Min-cost GCD (GA9_mcg) C++14
컴파일 오류
0 ms 0 KB
#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
#include <map>
using namespace std;
long long a, b, P, Q, C1, C2, TC1, TC2;
typedef long long ll;
const ll INF = (ll)1e18 + 5;
 
typedef pair<ll,ll> pll;
map<pll, ll> &ans;
map<pll, ll> tmp[100005];

ll mul (ll a, ll b) {
    if((double)INF / a < b) return INF;
    return a * b;
}
long long  gcd_cost_quite_fast (long long a, long long  b) {
    if(a == 0 || b == 0)return 0;
    if(ans.count(pll(a,b)) == 1) return ans[pll(a,b)];
     
    long long ret = 0;
     
    if(a >= b) {
        //correct
        ret = gcd_cost_quite_fast(b, a%b) + P;
        ret = min(ret, gcd_cost_quite_fast(a%b, b) + mul(Q, a/b));
    }else {
        ret = gcd_cost_quite_fast(a, b%a) + min(P+P, mul(Q, (b/a)));
    }
     
    return ans[pll(a,b)] = ret;
}
 
int main()
{
    int T;
    scanf("%d", &T);
    while (T--){
        scanf("%lld%lld", &a, &b);
        scanf("%lld%lld", &P, &Q);
        ans = tmp[T];//.clear();
        printf("%lld\n",gcd_cost_quite_fast(a, b));
    }
}

Compilation message

mcg.cpp:1:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)
 ^
mcg.cpp:11:15: error: ‘ans’ declared as reference but not initialized
 map<pll, ll> &ans;
               ^
mcg.cpp: In function ‘int main()’:
mcg.cpp:38:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &T);
                    ^
mcg.cpp:40:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a, &b);
                                  ^
mcg.cpp:41:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &P, &Q);
                                  ^