답안 #12688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
12688 2014-12-30T07:32:30 Z gs14004 Min-cost GCD (GA9_mcg) C++
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
 
typedef long long lint;
lint dp[100], dp2[100];
lint pow[19] = {1,0}; 
lint a,b,p,q;

inline bool calc_valid(lint x, lint y){
  	int t = lower_bound(pow,pow+19,x) - pow + lower_bound(pow,pow+19,y) - pow;
    return t < 18;
}
 
lint f(lint x, lint y, int step){
    if(x == 0 || y == 0) return 0;
    if(x >= y){
        if(~dp[step]) return dp[step];
        if(!calc_valid(q,x/y)) return dp[step] = f(y,x%y,step+1) + p;
        else return dp[step] = min(f(y,x%y,step+1) + p,f(x%y,y,step+1) + q*(x/y));
    }
    else{
      	if(~dp2[step]) return dp2[step];
        if(!calc_valid(q,y/x)) return 5e18;
        else return dp2[step] = f(x,y%x,step+1) + q * (y/x);
    }
}
 
void solve(){
    memset(dp,-1,sizeof(dp));
    memset(dp2,-1,sizeof(dp2));
    scanf("%lld %lld %lld %lld",&a,&b,&p,&q);
    if(a < b) printf("%lld\n",min(p + f(b,a,0),f(a,b,0)));
    else printf("%lld\n",f(a,b,0));
}
 
int main(){
  	for(int i=1; i<=18; i++) pow[i] = pow[i-1] * 10;
    int t;
    scanf("%d",&t);
    while (t--) {
        solve();
    }
}

Compilation message

mcg.cpp:9:12: error: ‘lint pow [19]’ redeclared as different kind of symbol
 lint pow[19] = {1,0}; 
            ^
In file included from /usr/include/features.h:374:0,
                 from /usr/include/x86_64-linux-gnu/c++/4.9/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/4.9/bits/c++config.h:430,
                 from /usr/include/c++/4.9/cstdio:41,
                 from mcg.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:153:1: note: previous declaration ‘double pow(double, double)’
 __MATHCALL (pow,, (_Mdouble_ __x, _Mdouble_ __y));
 ^
mcg.cpp: In function ‘bool calc_valid(lint, lint)’:
mcg.cpp:13:32: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator+’
    int t = lower_bound(pow,pow+19,x) - pow + lower_bound(pow,pow+19,y) - pow;
                                ^
mcg.cpp:13:66: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator+’
    int t = lower_bound(pow,pow+19,x) - pow + lower_bound(pow,pow+19,y) - pow;
                                                                  ^
mcg.cpp: In function ‘int main()’:
mcg.cpp:40:34: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
    for(int i=1; i<=18; i++) pow[i] = pow[i-1] * 10;
                                  ^
mcg.cpp:40:45: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
    for(int i=1; i<=18; i++) pow[i] = pow[i-1] * 10;
                                             ^
mcg.cpp: In function ‘void solve()’:
mcg.cpp:34:45: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld %lld %lld",&a,&b,&p,&q);
                                             ^
mcg.cpp: In function ‘int main()’:
mcg.cpp:42:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&t);
                   ^