# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27206 | 2017-07-10T13:21:17 Z | TAMREF | Min-cost GCD (GA9_mcg) | C++11 | 1000 ms | 32768 KB |
#include <bits/stdc++.h> #define va first #define vb second #define mp make_pair using namespace std; typedef unsigned long ll; typedef pair<int,int> pll; map<pll,int> m; pll x[100005]; ll s[100005], t[100005]; int idx; int rec(pll p){ if(!p.va||!p.vb) return 0; if(m[p]) return m[p]; ll x=p.va,y=p.vb; return m[p]=min(rec(mp(y,x%y))+s[idx],rec(x>=y?mp(x-y,y):mp(x,y-x))+t[idx]); } int main(){ int T; scanf("%d",&T); for(idx=0;idx<T;idx++){ scanf("%d%d%d%d",&x[idx].va,&x[idx].vb,&s[idx],&t[idx]); } if(*min_element(s,s+T)==*max_element(s,s+T) && *min_element(t,t+T)==*max_element(t,t+T)) for(idx=0;idx<T;idx++) printf("%d\n",rec(x[idx])); else{ for(idx=0;idx<T;idx++){ m.clear(); printf("%d\n",rec(x[idx])); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 4368 KB | Output is correct |
2 | Correct | 0 ms | 4368 KB | Output is correct |
3 | Correct | 0 ms | 4368 KB | Output is correct |
4 | Correct | 0 ms | 4368 KB | Output is correct |
5 | Correct | 0 ms | 4368 KB | Output is correct |
6 | Correct | 0 ms | 4368 KB | Output is correct |
7 | Correct | 0 ms | 4368 KB | Output is correct |
8 | Correct | 0 ms | 4368 KB | Output is correct |
9 | Correct | 0 ms | 4368 KB | Output is correct |
10 | Correct | 0 ms | 4368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Memory limit exceeded | 483 ms | 32768 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 89 ms | 6416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 21524 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |