답안 #920529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920529 2024-02-02T17:27:14 Z rainboy 물통 (KOI17_bucket) C++
100 / 100
3 ms 3420 KB
#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

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;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 1184 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 1184 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 1312 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 1184 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 1312 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 856 KB Output is correct
43 Correct 1 ms 1112 KB Output is correct
44 Correct 1 ms 688 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 3 ms 3420 KB Output is correct