Submission #83115

# Submission time Handle Problem Language Result Execution time Memory
83115 2018-11-05T12:15:52 Z chunghan None (KOI17_bucket) C++17
100 / 100
650 ms 25820 KB
#include<bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

map<pii, int> m;
int a, b, c, d;

ppi p(int i, int j, int k) {
    return ppi(pii(i, j), k);
}

void solve() {
    queue<ppi> q;
    q.push(p(0, 0, 0));
    while(q.size() != 0) {
        ppi t = q.front();
        q.pop();
        int i = t.first.first, j = t.first.second, k = t.second;
        m.insert(p(i, j, k));
        if(m.insert(p(0, j, k+1)).second) q.push(p(0, j, k+1));
        if(m.insert(p(i, 0, k+1)).second) q.push(p(i, 0, k+1));
        if(m.insert(p(a, j, k+1)).second) q.push(p(a, j, k+1));
        if(m.insert(p(i, b, k+1)).second) q.push(p(i, b, k+1));
        int u = min(b-j, i);
        if(m.insert(p(i-u, j+u, k+1)).second) q.push(p(i-u, j+u, k+1));
        u = min(a-i, j);
        if(m.insert(p(i+u, j-u, k+1)).second) q.push(p(i+u, j-u, k+1));
    }
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> a >> b >> c >> d;
    solve();
    int r = m.find(pii(c, d))->second;
    if(!c && !d) cout << 0;
    else cout << (r > 0 ? r : -1);
    return 0;
}
# 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 2 ms 408 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 12 ms 1252 KB Output is correct
7 Correct 61 ms 4104 KB Output is correct
8 Correct 257 ms 13128 KB Output is correct
9 Correct 255 ms 13160 KB Output is correct
10 Correct 2 ms 13160 KB Output is correct
11 Correct 2 ms 13160 KB Output is correct
12 Correct 2 ms 13160 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 2 ms 408 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 12 ms 1252 KB Output is correct
7 Correct 61 ms 4104 KB Output is correct
8 Correct 257 ms 13128 KB Output is correct
9 Correct 255 ms 13160 KB Output is correct
10 Correct 2 ms 13160 KB Output is correct
11 Correct 2 ms 13160 KB Output is correct
12 Correct 2 ms 13160 KB Output is correct
13 Correct 2 ms 13160 KB Output is correct
14 Correct 2 ms 13160 KB Output is correct
15 Correct 2 ms 13160 KB Output is correct
16 Correct 2 ms 13160 KB Output is correct
17 Correct 2 ms 13160 KB Output is correct
18 Correct 2 ms 13160 KB Output is correct
19 Correct 2 ms 13160 KB Output is correct
20 Correct 2 ms 13160 KB Output is correct
21 Correct 2 ms 13160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 13160 KB Output is correct
2 Correct 3 ms 13160 KB Output is correct
3 Correct 3 ms 13160 KB Output is correct
4 Correct 2 ms 13160 KB Output is correct
5 Correct 3 ms 13160 KB Output is correct
6 Correct 3 ms 13160 KB Output is correct
7 Correct 3 ms 13160 KB Output is correct
8 Correct 4 ms 13160 KB Output is correct
9 Correct 2 ms 13160 KB Output is correct
10 Correct 2 ms 13160 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 2 ms 408 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 12 ms 1252 KB Output is correct
7 Correct 61 ms 4104 KB Output is correct
8 Correct 257 ms 13128 KB Output is correct
9 Correct 255 ms 13160 KB Output is correct
10 Correct 2 ms 13160 KB Output is correct
11 Correct 2 ms 13160 KB Output is correct
12 Correct 2 ms 13160 KB Output is correct
13 Correct 2 ms 13160 KB Output is correct
14 Correct 2 ms 13160 KB Output is correct
15 Correct 2 ms 13160 KB Output is correct
16 Correct 2 ms 13160 KB Output is correct
17 Correct 2 ms 13160 KB Output is correct
18 Correct 2 ms 13160 KB Output is correct
19 Correct 2 ms 13160 KB Output is correct
20 Correct 2 ms 13160 KB Output is correct
21 Correct 2 ms 13160 KB Output is correct
22 Correct 3 ms 13160 KB Output is correct
23 Correct 3 ms 13160 KB Output is correct
24 Correct 2 ms 13160 KB Output is correct
25 Correct 3 ms 13160 KB Output is correct
26 Correct 3 ms 13160 KB Output is correct
27 Correct 3 ms 13160 KB Output is correct
28 Correct 4 ms 13160 KB Output is correct
29 Correct 2 ms 13160 KB Output is correct
30 Correct 2 ms 13160 KB Output is correct
31 Correct 14 ms 13160 KB Output is correct
32 Correct 22 ms 13160 KB Output is correct
33 Correct 192 ms 13220 KB Output is correct
34 Correct 17 ms 13220 KB Output is correct
35 Correct 8 ms 13220 KB Output is correct
36 Correct 4 ms 13220 KB Output is correct
37 Correct 16 ms 13220 KB Output is correct
38 Correct 23 ms 13220 KB Output is correct
39 Correct 18 ms 13220 KB Output is correct
40 Correct 8 ms 13220 KB Output is correct
41 Correct 53 ms 13220 KB Output is correct
42 Correct 60 ms 13220 KB Output is correct
43 Correct 32 ms 13220 KB Output is correct
44 Correct 19 ms 13220 KB Output is correct
45 Correct 650 ms 25820 KB Output is correct
46 Correct 2 ms 13160 KB Output is correct