Submission #920529

#TimeUsernameProblemLanguageResultExecution timeMemory
920529rainboy물통 (KOI17_bucket)C++98
100 / 100
3 ms3420 KiB
#include <stdio.h> #define N 100000 #define M 100000 #define N_ ((N + 1) * 2 + (M + 1) * 2) int main() { static int dd[N_], qu[N_]; int n, m, n_, cnt, h, a, a_, b, b_, u, v, d; scanf("%d%d%d%d", &n, &m, &a_, &b_), n_ = (n + 1) * 2 + (m + 1) * 2; for (u = 0; u < n_; u++) dd[u] = n_; cnt = 0; dd[0] = 0, qu[cnt++] = 0; for (h = 0; h < cnt; h++) { u = qu[h], d = dd[u]; if (u <= n) a = u, b = 0; else if ((u -= n + 1) <= n) a = u, b = m; else if ((u -= n + 1) <= m) a = 0, b = u; else { u -= m + 1; a = n, b = u; } if (a == a_ && b == b_) { printf("%d\n", d); return 0; } d++; v = a; if (dd[v] > d) dd[v] = d, qu[cnt++] = v; v = (n + 1) + a; if (dd[v] > d) dd[v] = d, qu[cnt++] = v; v = (n + 1) * 2 + b; if (dd[v] > d) dd[v] = d, qu[cnt++] = v; v = (n + 1) * 2 + (m + 1) + b; if (dd[v] > d) dd[v] = d, qu[cnt++] = v; v = a + b <= m ? (n + 1) * 2 + a + b : (n + 1) + a + b - m; if (dd[v] > d) dd[v] = d, qu[cnt++] = v; v = a + b <= n ? a + b : (n + 1) * 2 + (m + 1) + a + b - n; if (dd[v] > d) dd[v] = d, qu[cnt++] = v; } printf("-1\n"); return 0; }

Compilation message (stderr)

bucket.cpp: In function 'int main()':
bucket.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d%d%d", &n, &m, &a_, &b_), n_ = (n + 1) * 2 + (m + 1) * 2;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...