Submission #944564

# Submission time Handle Problem Language Result Execution time Memory
944564 2024-03-13T00:31:16 Z rainboy 수족관 3 (KOI13_aqua3) C
100 / 100
67 ms 12888 KB
#include <stdio.h>
#include <string.h>

#define N	150000

int min(int a, int b) { return a < b ? a : b; }

unsigned int X = 12345;

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

long long aa[N];

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

		while (j < k)
			if (aa[ii[j]] == aa[i_])
				j++;
			else if (aa[ii[j]] < aa[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int main() {
	static int xx[N + 1], yy[N], ll[N], rr[N], pp[N], qu[N], dd[N], ii[N], jj[N];
	int n, k, cnt, h, i, i_, j, p;
	long long area;

	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]]++;
	}
	memset(jj, -1, n * sizeof *jj);
	cnt = 0;
	for (i = 0; i < n; i++) {
		i_ = i;
		while (dd[i_] == 0) {
			p = pp[i_], j = jj[i_];
			aa[i_] = (j == -1 ? 0 : aa[j]) + (long long) (xx[rr[i_]] - xx[ll[i_] + 1]) * (yy[i_] - (p == -1 ? 0 : yy[p]));
			dd[i_] = -1;
			if (p == -1)
				break;
			dd[p]--;
			if (jj[p] == -1)
				jj[p] = i_;
			else if (aa[jj[p]] < aa[i_]) {
				if (jj[p] != -1)
					ii[cnt++] = jj[p];
				jj[p] = i_;
			} else
				ii[cnt++] = i_;
			i_ = p;
		}
	}
	for (i = 0; i < n; i++)
		if (pp[i] == -1) {
			ii[cnt++] = i;
			break;
		}
	sort(ii, 0, cnt);
	scanf("%d", &k), k = min(k, cnt);
	area = 0;
	for (h = cnt - k; h < cnt; h++)
		area += aa[ii[h]];
	printf("%lld\n", area);
	return 0;
}

Compilation message

aqua3.c: In function 'main':
aqua3.c:60:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   60 |   pp[i] = rr[i] == n || ll[i] != -1 && yy[ll[i]] > yy[rr[i]] ? ll[i] : rr[i];
      |                         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
aqua3.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%*d%*d", &n), n = n / 2 - 1;
      |  ^~~~~~~~~~~~~~~~~~~~~
aqua3.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%*d%*d%d%d", &xx[i + 1], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aqua3.c:44:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%*d%*d");
      |  ^~~~~~~~~~~~~~~
aqua3.c:92:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |  scanf("%d", &k), k = min(k, cnt);
      |  ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 11600 KB Output is correct
2 Correct 52 ms 11604 KB Output is correct
3 Correct 54 ms 12372 KB Output is correct
4 Correct 54 ms 12416 KB Output is correct
5 Correct 62 ms 12504 KB Output is correct
6 Correct 47 ms 12544 KB Output is correct
7 Correct 51 ms 12500 KB Output is correct
8 Correct 51 ms 12628 KB Output is correct
9 Correct 55 ms 12604 KB Output is correct
10 Correct 56 ms 12624 KB Output is correct
11 Correct 46 ms 12592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 11440 KB Output is correct
2 Correct 50 ms 11644 KB Output is correct
3 Correct 55 ms 12372 KB Output is correct
4 Correct 59 ms 12436 KB Output is correct
5 Correct 54 ms 12796 KB Output is correct
6 Correct 47 ms 12628 KB Output is correct
7 Correct 52 ms 12660 KB Output is correct
8 Correct 52 ms 12660 KB Output is correct
9 Correct 55 ms 12628 KB Output is correct
10 Correct 60 ms 12624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 11624 KB Output is correct
2 Correct 50 ms 11420 KB Output is correct
3 Correct 67 ms 12476 KB Output is correct
4 Correct 59 ms 12888 KB Output is correct
5 Correct 54 ms 12536 KB Output is correct
6 Correct 53 ms 12320 KB Output is correct
7 Correct 54 ms 12488 KB Output is correct
8 Correct 55 ms 12624 KB Output is correct
9 Correct 62 ms 12628 KB Output is correct