Submission #112694

#TimeUsernameProblemLanguageResultExecution timeMemory
112694arnold518물통 (KOI17_bucket)C++14
100 / 100
597 ms25456 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int a, b, c, d; struct Queue { int x, y, v; }; map<pii, int> vis; queue<Queue> Q; void enque(Queue p) { if(vis.count({p.x, p.y})) return; vis[{p.x, p.y}]=p.v; Q.push(p); } int main() { int i, j; scanf("%d%d%d%d", &a, &b, &c, &d); Q.push({0, 0, 0}); vis[{0, 0}]; while(!Q.empty()) { Queue now=Q.front(); Q.pop(); int s=now.x+now.y; Queue nxt; nxt.v=now.v+1; nxt.y=min(s, b); nxt.x=s-nxt.y; enque(nxt); nxt.x=min(s, a); nxt.y=s-nxt.x; enque(nxt); nxt.x=a; nxt.y=now.y; enque(nxt); nxt.x=now.x; nxt.y=b; enque(nxt); nxt.x=0; nxt.y=now.y; enque(nxt); nxt.x=now.x; nxt.y=0; enque(nxt); } if(vis.count({c, d})) printf("%d", vis[{c, d}]); else printf("-1"); }

Compilation message (stderr)

bucket.cpp: In function 'int main()':
bucket.cpp:25:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
bucket.cpp:25:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
bucket.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &a, &b, &c, &d);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...