# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
58808 | 2018-07-19T14:14:52 Z | sansae | 물통 (KOI17_bucket) | C++14 | 4 ms | 640 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(b!=d){ ans1++; } } else if(d==e){ if(b!=0){ ans1++; } ans1++; if(c!=0){ ans1++; } } } else if(bb==e){ if(c==e){ if(a!=0){ ans1++; } ans1++; if(d!=0){ ans1++; } } else if(d==e){ if(a!=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(b!=d){ ans2++; } } else if(d==e){ if(b!=0){ ans2++; } ans2++; if(c!=0){ ans2++; } } } else if(bb==e){ if(c==e){ if(a!=0){ ans2++; } ans2++; if(d!=0){ ans2++; } } else if(d==e){ if(a!=c){ ans2++; } } } printf("%d", min(ans1, ans2)); } } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 2 ms | 544 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Incorrect | 3 ms | 604 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 2 ms | 544 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Incorrect | 3 ms | 604 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 3 ms | 640 KB | Output is correct |
3 | Correct | 4 ms | 640 KB | Output is correct |
4 | Correct | 3 ms | 640 KB | Output is correct |
5 | Correct | 3 ms | 640 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 2 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 2 ms | 544 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Incorrect | 3 ms | 604 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |