답안 #894725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894725 2023-12-28T19:16:43 Z rainboy 물탱크 (KOI18_watertank) C
100 / 100
416 ms 47320 KB
#include <stdio.h>
#include <string.h>

#define L	1000
#define W	1000
#define N	(L * W + 1)
#define M	((L + 1) * W + L * (W + 1))

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int ii[M], jj[M], yy[M];

void sort(int *hh, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (yy[hh[j]] == yy[h])
				j++;
			else if (yy[hh[j]] < yy[h]) {
				tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
			}
		sort(hh, l, i);
		l = k;
	}
}

int ds[N], sz[N];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j, sz[j] += sz[i];
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i, sz[i] += sz[j];
	}
}

int main() {
	static int hh[M];
	int l, w, y_, n, m, h, h_, i, x, y, z, ans;

	scanf("%d%d%d", &l, &w, &y_);
	n = l * w + 1, m = 0;
	for (z = -1; z < l; z++)
		for (x = 0; x < w; x++) {
			scanf("%d", &y);
			if (y == -1)
				y = y_;
			ii[m] = z < 0 ? n - 1 : z * w + x, jj[m] = z + 1 == l ? n - 1 : (z + 1) * w + x, yy[m] = y, m++;
		}
	for (z = 0; z < l; z++)
		for (x = -1; x < w; x++) {
			scanf("%d", &y);
			if (y == -1)
				y = y_;
			ii[m] = x < 0 ? n - 1 : z * w + x, jj[m] = x + 1 == w ? n - 1 : z * w + (x + 1), yy[m] = y, m++;
		}
	for (h = 0; h < m; h++)
		hh[h] = h;
	sort(hh, 0, m);
	memset(ds, -1, n * sizeof *ds);
	for (i = 0; i < n; i++)
		sz[i] = 1;
	ans = l * w * y_;
	for (h = 0; h < m; h++) {
		h_ = hh[h];
		join(ii[h_], jj[h_]);
		ans -= (sz[find(n - 1)] - 1) * ((h + 1 == m ? y_ : yy[hh[h + 1]]) - yy[h_]);
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

watertank.c: In function 'main':
watertank.c:60:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%d%d%d", &l, &w, &y_);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
watertank.c:64:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |    scanf("%d", &y);
      |    ^~~~~~~~~~~~~~~
watertank.c:71:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |    scanf("%d", &y);
      |    ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10680 KB Output is correct
6 Correct 1 ms 10692 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 45368 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 129 ms 43308 KB Output is correct
4 Correct 154 ms 43944 KB Output is correct
5 Correct 1 ms 10584 KB Output is correct
6 Correct 175 ms 44324 KB Output is correct
7 Correct 125 ms 43188 KB Output is correct
8 Correct 145 ms 43684 KB Output is correct
9 Correct 123 ms 42916 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 158 ms 43440 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10584 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 1 ms 10676 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10700 KB Output is correct
8 Correct 2 ms 10584 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 141 ms 45448 KB Output is correct
7 Correct 2 ms 10696 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 118 ms 43832 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 153 ms 45332 KB Output is correct
13 Correct 115 ms 43188 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 230 ms 43844 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 148 ms 43808 KB Output is correct
20 Correct 2 ms 10584 KB Output is correct
21 Correct 416 ms 47320 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10740 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 310 ms 46316 KB Output is correct
29 Correct 191 ms 44372 KB Output is correct
30 Correct 125 ms 43296 KB Output is correct
31 Correct 142 ms 43448 KB Output is correct
32 Correct 196 ms 44712 KB Output is correct
33 Correct 1 ms 10584 KB Output is correct
34 Correct 133 ms 42920 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10588 KB Output is correct
38 Correct 178 ms 43676 KB Output is correct
39 Correct 264 ms 45484 KB Output is correct
40 Correct 1 ms 10584 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 155 ms 44200 KB Output is correct
45 Correct 331 ms 45476 KB Output is correct
46 Correct 2 ms 10584 KB Output is correct