Submission #12117

#TimeUsernameProblemLanguageResultExecution timeMemory
12117tncks0121Min-cost GCD (GA9_mcg)C++14
Compilation error
0 ms0 KiB
#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> tmp[100005]; map<pll, ll> *ans; 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 (stderr)

mcg.cpp:1:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)
 ^
mcg.cpp: In function ‘long long int gcd_cost_quite_fast(long long int, long long int)’:
mcg.cpp:20:45: error: no match for ‘operator[]’ (operand types are ‘std::map<std::pair<long long int, long long int>, long long int>*’ and ‘pll {aka std::pair<long long int, long long int>}’)
     if(ans->count(pll(a,b)) == 1) return ans[pll(a,b)];
                                             ^
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);
                                  ^