답안 #944505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944505 2024-03-12T20:24:32 Z rainboy 수족관 1 (KOI13_aqua1) C
100 / 100
2 ms 600 KB
#include <stdio.h>

#define N	2500

int main() {
	static int xx[N + 1], yy[N], ll[N], rr[N], pp[N], qu[N];
	static char empty[N];
	int n, k, cnt, i, lower, upper, x, ans;

	scanf("%d%*d%*d", &n), n = n / 2 - 1;
	xx[0] = 0;
	for (i = 0; i < n; i++)
		scanf("%*d%*d%d%d", &xx[i + 1], &yy[i]);
	scanf("%*d%*d");
	cnt = 0;
	for (i = 0; i < n; i++) {
		while (cnt && yy[qu[cnt - 1]] > yy[i])
			cnt--;
		ll[i] = cnt == 0 ? -1 : qu[cnt - 1];
		qu[cnt++] = i;
	}
	cnt = 0;
	for (i = n - 1; i >= 0; i--) {
		while (cnt && yy[qu[cnt - 1]] >= yy[i])
			cnt--;
		rr[i] = cnt == 0 ? n : qu[cnt - 1];
		qu[cnt++] = i;
	}
	for (i = 0; i < n; i++)
		pp[i] = rr[i] == n || ll[i] != -1 && yy[ll[i]] > yy[rr[i]] ? ll[i] : rr[i];
	scanf("%d", &k);
	while (k--) {
		scanf("%d%*d%*d%*d", &x);
		lower = 0, upper = n;
		while (upper - lower > 1) {
			i = (lower + upper) / 2;
			if (xx[i] <= x)
				lower = i;
			else
				upper = i;
		}
		i = lower;
		while (i != -1 && !empty[i])
			empty[i] = 1, i = pp[i];
	}
	ans = 0;
	for (i = 0; i < n; i++)
		if (!empty[i])
			ans += (xx[rr[i]] - xx[ll[i] + 1]) * (yy[i] - yy[pp[i]]);
	printf("%d\n", ans);
	return 0;
}

Compilation message

aqua1.c: In function 'main':
aqua1.c:30:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   30 |   pp[i] = rr[i] == n || ll[i] != -1 && yy[ll[i]] > yy[rr[i]] ? ll[i] : rr[i];
      |                         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
aqua1.c:10:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%d%*d%*d", &n), n = n / 2 - 1;
      |  ^~~~~~~~~~~~~~~~~~~~~
aqua1.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%*d%*d%d%d", &xx[i + 1], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aqua1.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%*d%*d");
      |  ^~~~~~~~~~~~~~~
aqua1.c:31:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d", &k);
      |  ^~~~~~~~~~~~~~~
aqua1.c:33:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d%*d%*d%*d", &x);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 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 344 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 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 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 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct