Submission #83110

#TimeUsernameProblemLanguageResultExecution timeMemory
83110chunghan물통 (KOI17_bucket)C++17
34 / 100
5 ms1148 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...