Submission #83113

# Submission time Handle Problem Language Result Execution time Memory
83113 2018-11-05T12:10:50 Z chunghan None (KOI17_bucket) C++17
34 / 100
4 ms 892 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;
    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 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 4 ms 572 KB Output is correct
5 Incorrect 2 ms 572 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 4 ms 572 KB Output is correct
5 Incorrect 2 ms 572 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 572 KB Output is correct
2 Correct 3 ms 672 KB Output is correct
3 Correct 3 ms 688 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 3 ms 748 KB Output is correct
6 Correct 3 ms 764 KB Output is correct
7 Correct 3 ms 764 KB Output is correct
8 Correct 4 ms 892 KB Output is correct
9 Correct 2 ms 892 KB Output is correct
10 Correct 2 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 4 ms 572 KB Output is correct
5 Incorrect 2 ms 572 KB Output isn't correct
6 Halted 0 ms 0 KB -