답안 #83110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83110 2018-11-05T12:02:51 Z chunghan 물통 (KOI17_bucket) C++17
34 / 100
5 ms 1148 KB
#include<bits/stdc++.h>

using namespace std;

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

map<pii, int> m;
set<pii> s;
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(s.insert(pii(0, j)).second) q.push(p(0, j, k+1));
        if(s.insert(pii(i, 0)).second) q.push(p(i, 0, k+1));
        if(s.insert(pii(a, j)).second) q.push(p(a, j, k+1));
        if(s.insert(pii(i, b)).second) q.push(p(i, b, k+1));
        int u = min(b-j, i);
        if(s.insert(pii(i-u, j+u)).second) q.push(p(i-u, j+u, k+1));
        u = min(a-i, j);
        if(s.insert(pii(i+u, j-u)).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(r) cout << r;
    else cout << -1;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 5 ms 812 KB Output is correct
5 Incorrect 2 ms 812 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 5 ms 812 KB Output is correct
5 Incorrect 2 ms 812 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 812 KB Output is correct
2 Correct 4 ms 956 KB Output is correct
3 Correct 3 ms 956 KB Output is correct
4 Correct 3 ms 956 KB Output is correct
5 Correct 3 ms 956 KB Output is correct
6 Correct 4 ms 956 KB Output is correct
7 Correct 4 ms 956 KB Output is correct
8 Correct 5 ms 1148 KB Output is correct
9 Correct 2 ms 1148 KB Output is correct
10 Correct 2 ms 1148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 5 ms 812 KB Output is correct
5 Incorrect 2 ms 812 KB Output isn't correct
6 Halted 0 ms 0 KB -