# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58818 | 2018-07-19T14:33:34 Z | sansae | None (KOI17_bucket) | C++14 | 4 ms | 840 KB |
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <vector> #include <queue> #include <set> #include <map> #include <iostream> #include <deque> #include <algorithm> #include <functional> using namespace std; int gcd(int a, int b){ if(a==0){ return b; } else if(b==0){ return a; } else{ return a<b ? gcd(a, b%a) : gcd(b, a%b); } } int main(void){ int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); if(c!=0 && d!=0 && c!=a && d!=b){ printf("-1"); return 0; } else{ int g=gcd(a, b); if(c%g!=0 || d%g!=0){ printf("-1"); return 0; } else{ c/=g; d/=g; a/=g; b/=g; if(c==0 && d==0){ printf("0"); return 0; } else if(c==a && d==0){ printf("1"); return 0; } else if(c==0 && d==b){ printf("1"); return 0; } else if(c==a && d==b){ printf("2"); return 0; } else{ int e; if(c!=0 && c!=a){ e=c; } if(d!=0 && d!=b){ e=d; } int aa, bb; int ans1=0; int ans2=0; aa=0; bb=0; while(aa!=e && bb!=e){ if(aa==0){ aa=a; ans1++; } else if(aa==a){ if(aa+bb>=b){ aa=aa+bb-b; bb=b; } else{ aa=0; bb+=a; } ans1++; } else if(bb==b){ bb=0; ans1++; } else{ bb=aa; aa=0; ans1++; } } if(aa==e){ if(c==e){ if(bb!=d){ ans1++; } } else if(d==e){ if(bb!=0){ ans1++; } ans1++; if(c!=0){ ans1++; } } } else if(bb==e){ if(c==e){ if(aa!=0){ ans1++; } ans1++; if(d!=0){ ans1++; } if(aa==0 && d==0){ ans1--; } } else if(d==e){ if(aa!=c){ ans1++; } } } aa=0; bb=0; while(aa!=e && bb!=e){ if(bb==0){ bb=b; ans2++; } else if(aa==a){ aa=0; ans2++; } else if(aa==0){ if(bb<=a){ aa=bb; bb=0; ans2++; } else{ bb=bb+aa-a; aa=a; ans2++; } } else{ bb=bb+aa-a; aa=a; ans2++; } } if(aa==e){ if(c==e){ if(bb!=d){ ans2++; } } else if(d==e){ if(bb==0&&c==0){ ans2++; } else if(bb==b && c==0){ ans2+=2; } else if(bb==0 && c==a){ ans2+=2; } else{ ans2+=3; } } } else if(bb==e){ if(c==e){ if(aa==0 && d==0){ ans2++; } else if(aa==0 && d==b){ ans2+=2; } else if(aa==a && d==0){ ans2+=2; } else{ ans2+=2; } } else if(d==e){ if(aa!=c){ ans2++; } } } printf("%d", min(ans1, ans2)); } } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 3 ms | 416 KB | Output is correct |
4 | Correct | 2 ms | 496 KB | Output is correct |
5 | Correct | 3 ms | 584 KB | Output is correct |
6 | Correct | 2 ms | 584 KB | Output is correct |
7 | Correct | 2 ms | 584 KB | Output is correct |
8 | Correct | 2 ms | 584 KB | Output is correct |
9 | Correct | 2 ms | 584 KB | Output is correct |
10 | Correct | 2 ms | 584 KB | Output is correct |
11 | Correct | 3 ms | 632 KB | Output is correct |
12 | Correct | 2 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 3 ms | 416 KB | Output is correct |
4 | Correct | 2 ms | 496 KB | Output is correct |
5 | Correct | 3 ms | 584 KB | Output is correct |
6 | Correct | 2 ms | 584 KB | Output is correct |
7 | Correct | 2 ms | 584 KB | Output is correct |
8 | Correct | 2 ms | 584 KB | Output is correct |
9 | Correct | 2 ms | 584 KB | Output is correct |
10 | Correct | 2 ms | 584 KB | Output is correct |
11 | Correct | 3 ms | 632 KB | Output is correct |
12 | Correct | 2 ms | 632 KB | Output is correct |
13 | Correct | 2 ms | 680 KB | Output is correct |
14 | Correct | 2 ms | 680 KB | Output is correct |
15 | Correct | 3 ms | 680 KB | Output is correct |
16 | Correct | 2 ms | 680 KB | Output is correct |
17 | Correct | 3 ms | 680 KB | Output is correct |
18 | Correct | 2 ms | 840 KB | Output is correct |
19 | Correct | 3 ms | 840 KB | Output is correct |
20 | Correct | 3 ms | 840 KB | Output is correct |
21 | Correct | 2 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 840 KB | Output is correct |
2 | Correct | 4 ms | 840 KB | Output is correct |
3 | Correct | 3 ms | 840 KB | Output is correct |
4 | Correct | 2 ms | 840 KB | Output is correct |
5 | Correct | 3 ms | 840 KB | Output is correct |
6 | Correct | 4 ms | 840 KB | Output is correct |
7 | Correct | 3 ms | 840 KB | Output is correct |
8 | Correct | 3 ms | 840 KB | Output is correct |
9 | Correct | 3 ms | 840 KB | Output is correct |
10 | Correct | 2 ms | 840 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 3 ms | 416 KB | Output is correct |
4 | Correct | 2 ms | 496 KB | Output is correct |
5 | Correct | 3 ms | 584 KB | Output is correct |
6 | Correct | 2 ms | 584 KB | Output is correct |
7 | Correct | 2 ms | 584 KB | Output is correct |
8 | Correct | 2 ms | 584 KB | Output is correct |
9 | Correct | 2 ms | 584 KB | Output is correct |
10 | Correct | 2 ms | 584 KB | Output is correct |
11 | Correct | 3 ms | 632 KB | Output is correct |
12 | Correct | 2 ms | 632 KB | Output is correct |
13 | Correct | 2 ms | 680 KB | Output is correct |
14 | Correct | 2 ms | 680 KB | Output is correct |
15 | Correct | 3 ms | 680 KB | Output is correct |
16 | Correct | 2 ms | 680 KB | Output is correct |
17 | Correct | 3 ms | 680 KB | Output is correct |
18 | Correct | 2 ms | 840 KB | Output is correct |
19 | Correct | 3 ms | 840 KB | Output is correct |
20 | Correct | 3 ms | 840 KB | Output is correct |
21 | Correct | 3 ms | 840 KB | Output is correct |
22 | Correct | 4 ms | 840 KB | Output is correct |
23 | Correct | 3 ms | 840 KB | Output is correct |
24 | Correct | 2 ms | 840 KB | Output is correct |
25 | Correct | 3 ms | 840 KB | Output is correct |
26 | Correct | 4 ms | 840 KB | Output is correct |
27 | Correct | 3 ms | 840 KB | Output is correct |
28 | Correct | 3 ms | 840 KB | Output is correct |
29 | Correct | 3 ms | 840 KB | Output is correct |
30 | Correct | 2 ms | 840 KB | Output is correct |
31 | Correct | 3 ms | 840 KB | Output is correct |
32 | Correct | 3 ms | 840 KB | Output is correct |
33 | Correct | 2 ms | 840 KB | Output is correct |
34 | Incorrect | 2 ms | 840 KB | Output isn't correct |
35 | Halted | 0 ms | 0 KB | - |