Submission #12115

#TimeUsernameProblemLanguageResultExecution timeMemory
12115tncks0121Min-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> &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 (stderr)

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);
                                  ^