Submission #140774

# Submission time Handle Problem Language Result Execution time Memory
140774 2019-08-05T02:56:23 Z khrbuddy03 None (KOI17_bucket) C++14
100 / 100
651 ms 24396 KB
#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
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 43 ms 2808 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 43 ms 2808 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 380 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 43 ms 2808 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 380 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 380 KB Output is correct
27 Correct 3 ms 380 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 4 ms 568 KB Output is correct
32 Correct 6 ms 760 KB Output is correct
33 Correct 195 ms 12792 KB Output is correct
34 Correct 4 ms 504 KB Output is correct
35 Correct 6 ms 632 KB Output is correct
36 Correct 4 ms 632 KB Output is correct
37 Correct 8 ms 888 KB Output is correct
38 Correct 22 ms 1656 KB Output is correct
39 Correct 8 ms 888 KB Output is correct
40 Correct 8 ms 1016 KB Output is correct
41 Correct 23 ms 2168 KB Output is correct
42 Correct 50 ms 4472 KB Output is correct
43 Correct 31 ms 2652 KB Output is correct
44 Correct 18 ms 1784 KB Output is correct
45 Correct 651 ms 24396 KB Output is correct
46 Correct 2 ms 376 KB Output is correct