# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
140774 | khrbuddy03 | 물통 (KOI17_bucket) | C++14 | 651 ms | 24396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, bool> vis;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int X, Y, A, B; cin >> X >> Y >> A >> B;
queue<pair<int, pair<int, int>>> q;
q.push(make_pair(0, make_pair(0, 0)));
vis[make_pair(0, 0)] = true;
while (!q.empty()) {
int dist = q.front().first;
int a = q.front().second.first, b = q.front().second.second;
// cout << dist << ' ' << a << ' ' << b << '\n';
q.pop();
if (a == A && b == B) {
cout << dist << '\n';
return 0;
}
pair<int, int> next[6] = {{a, Y}, {X, b}, {a - min(a, Y - b), b + min(a, Y - b)}, {a + min(b, X - a), b - min(b, X - a)}, {a, 0}, {0, b}};
for (int i = 0; i < 6; i++) {
if (vis[next[i]]) continue;
q.push(make_pair(dist + 1, next[i]));
vis[next[i]] = true;
}
}
cout << "-1\n";
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |