Submission #917346

# Submission time Handle Problem Language Result Execution time Memory
917346 2024-01-27T22:23:06 Z rainboy None (KOI17_cut) C++17
100 / 100
202 ms 34188 KB
#include <stdio.h>

#define N	1000000

unsigned int X = 12345;

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

int ll[N], rr[N], hh[N];

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) {
			int c = ll[hh[j]] != ll[h] ? ll[hh[j]] - ll[h] : rr[h] - rr[hh[j]];

			if (c == 0)
				j++;
			else if (c < 0) {
				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 main() {
	static int xx[N], yy[N];
	int n, m, h, h_, h1, i, j, tmp, x, y;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	i = -1;
	for (j = 0; j < n; j++)
		if ((yy[j] < 0) != (yy[(j + 1) % n] < 0))
			i = j;
	m = 0;
	for (j = 0; j < n; j++)
		if ((yy[j] < 0) != (yy[(j + 1) % n] < 0)) {
			if (yy[j] > 0) {
				ll[m] = xx[i], rr[m] = xx[j];
				if (ll[m] > rr[m])
					tmp = ll[m], ll[m] = rr[m], rr[m] = tmp;
				m++;
			}
			i = j;
		}
	for (h = 0; h < m; h++)
		hh[h] = h;
	sort(hh, 0, m);
	x = 0;
	for (h = 0, h1 = -1; h < m; h++) {
		h_ = hh[h];
		if (h1 == -1 || rr[h1] < rr[h_])
			h1 = h_, x++;
	}
	y = 0;
	for (h = m - 1, h1 = -1; h >= 0; h--) {
		h_ = hh[h];
		if (h1 == -1 || rr[h1] > rr[h_])
			h1 = h_, y++;
	}
	printf("%d %d\n", x, y);
	return 0;
}

Compilation message

cut.cpp: In function 'int main()':
cut.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
cut.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8736 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 3 ms 8740 KB Output is correct
25 Correct 4 ms 8836 KB Output is correct
26 Correct 3 ms 8796 KB Output is correct
27 Correct 3 ms 8632 KB Output is correct
28 Correct 3 ms 8796 KB Output is correct
29 Correct 4 ms 8796 KB Output is correct
30 Correct 3 ms 8824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8736 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 3 ms 8740 KB Output is correct
25 Correct 4 ms 8836 KB Output is correct
26 Correct 3 ms 8796 KB Output is correct
27 Correct 3 ms 8632 KB Output is correct
28 Correct 3 ms 8796 KB Output is correct
29 Correct 4 ms 8796 KB Output is correct
30 Correct 3 ms 8824 KB Output is correct
31 Correct 39 ms 12828 KB Output is correct
32 Correct 155 ms 28960 KB Output is correct
33 Correct 37 ms 12556 KB Output is correct
34 Correct 162 ms 27304 KB Output is correct
35 Correct 195 ms 33364 KB Output is correct
36 Correct 189 ms 33756 KB Output is correct
37 Correct 197 ms 34040 KB Output is correct
38 Correct 193 ms 33296 KB Output is correct
39 Correct 202 ms 34188 KB Output is correct
40 Correct 187 ms 33496 KB Output is correct
41 Correct 184 ms 33616 KB Output is correct
42 Correct 183 ms 32084 KB Output is correct
43 Correct 188 ms 31876 KB Output is correct
44 Correct 192 ms 32020 KB Output is correct
45 Correct 189 ms 32088 KB Output is correct