답안 #944539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944539 2024-03-12T22:25:15 Z rainboy 수족관 2 (KOI13_aqua2) C++17
0 / 100
74 ms 10836 KB
#include <math.h>
#include <stdio.h>

#define N	150000

int main() {
	static int xx[N + 1], yy[N], ll[N], rr[N], pp[N], qu[N], dd[N], kk[N];
	int n, k, cnt, i, j, lower, upper, x, area;
	double t;

	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];
		if (pp[i] != -1)
			dd[pp[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;
		}
		kk[lower]++;
	}
	for (i = 0; i < n; i++) {
		j = i;
		while (pp[j] != -1 && dd[j] == 0)
			kk[pp[j]] += kk[j], dd[pp[j]]--, j = pp[j];
	}
	t = 0, area = 0;
	for (i = 0; i < n; i++)
	 	if (kk[i] > 0)
			t += (double) (xx[rr[i]] - xx[ll[i] + 1]) * (yy[i] - yy[pp[i]]) / kk[i];
		else
			area += (long long) (xx[rr[i]] - xx[ll[i] + 1]) * (yy[i] - yy[pp[i]]);
	printf("%.2f\n", round(t * 1000) / 1000);
	printf("%d\n", area);
	return 0;
}

Compilation message

aqua2.cpp: In function 'int main()':
aqua2.cpp:31:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   31 |   pp[i] = rr[i] == n || ll[i] != -1 && yy[ll[i]] > yy[rr[i]] ? ll[i] : rr[i];
      |                         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
aqua2.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", &n), n = n / 2 - 1;
      |  ~~~~~^~~~~~~~~~~~~~~~
aqua2.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%*d%*d%d%d", &xx[i + 1], &yy[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aqua2.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%*d%*d");
      |  ~~~~~^~~~~~~~~~
aqua2.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
aqua2.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d%*d%*d%*d", &x);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Incorrect 1 ms 2392 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 10836 KB Output isn't correct
2 Halted 0 ms 0 KB -