Submission #711335

# Submission time Handle Problem Language Result Execution time Memory
711335 2023-03-16T15:32:25 Z rainboy Bulldozer (JOI17_bulldozer) C
100 / 100
1873 ms 135428 KB
#include <stdio.h>

#define N	2000
#define M	(N * (N - 1) / 2)
#define N_	(1 << 11)	/* N_ = pow2(ceil(log2(N))) */

long long max(long long a, long long b) { return a > b ? a : b; }

unsigned int X = 12345;

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

long long cross(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

long long dot(int x1, int y1, int x2, int y2) {
	return (long long) x1 * x2 + (long long) y1 * y2;
}

int xx[N], yy[N], ww[N], ii[N], idx[N], n;
int uu[M], vv[M], xx_[M], yy_[M], hh[M], m;

int compare_h(int h1, int h2) {
	int x1 = xx_[h1], y1 = yy_[h1];
	int x2 = xx_[h2], y2 = yy_[h2];
	long long c = cross(x1, y1, x2, y2);

	return c == 0 ? 0 : (c < 0 ? -1 : 1);
}

int x_, y_;

int compare_i(int i, int j) {
	long long c, d;

	c = cross(x_, y_, xx[i] - xx[j], yy[i] - yy[j]);
	if (c != 0)
		return c < 0 ? -1 : 1;
	d = dot(x_, y_, xx[i] - xx[j], yy[i] - yy[j]);
	return d == 0 ? 0 : (d < 0 ? -1 : 1);
}

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 = compare_h(hh[j], h);

			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;
	}
}

long long st[N_ * 2], ss[N_ * 2], pp[N_ * 2], qq[N_ * 2]; int n_;

void pul(int i) {
	int l = i << 1, r = l | 1;

	ss[i] = ss[l] + ss[r];
	pp[i] = max(pp[l], ss[l] + pp[r]);
	qq[i] = max(qq[l] + ss[r], qq[r]);
	st[i] = max(max(st[l], st[r]), qq[l] + pp[r]);
}

void build() {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (i = 0; i < n; i++) {
		int w = ww[ii[i]];

		ss[n_ + i] = w, st[n_ + i] = pp[n_ + i] = qq[n_ + i] = max(w, 0);
	}
	for (i = n_ - 1; i > 0; i--)
		pul(i);
}

void update(int i, int x) {
	i += n_;
	ss[i] = x, st[i] = pp[i] = qq[i] = max(x, 0);
	while (i > 1)
		pul(i >>= 1);
}

void bubble(int i) {
	int h, j;

	h = idx[i];
	if (h + 1 < n && compare_i(i, j = ii[h + 1]) > 0) {
		ii[idx[j] = h] = j, ii[idx[i] = h + 1] = i;
		update(h, ww[j]), update(h + 1, ww[i]);
		bubble(i), bubble(j);
	}
	h = idx[i];
	if (h > 0 && compare_i(i, j = ii[h - 1]) < 0) {
		ii[idx[j] = h] = j, ii[idx[i] = h - 1] = i;
		update(h, ww[j]), update(h - 1, ww[i]);
		bubble(i), bubble(j);
	}
}

int main() {
	int h, h_, i, j;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &xx[i], &yy[i], &ww[i]);
	if (n == 1) {
		printf("%lld\n", max(ww[0], 0));
		return 0;
	}
	m = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (xx[i] < xx[j] || xx[i] == xx[j] && yy[i] < yy[j])
				uu[m] = i, vv[m] = j, xx_[m] = xx[j] - xx[i], yy_[m] = yy[j] - yy[i], m++;
	for (h = 0; h < m; h++)
		hh[h] = h;
	sort(hh, 0, m);
	for (i = 0; i < n; i++)
		ii[idx[i] = i] = i;
	build();
	x_ = xx_[hh[0]], y_ = yy_[hh[0]];
	for (i = 0; i < n; i++)
		bubble(i);
	ans = 0;
	for (h = 0; h < m; h++) {
		h_ = hh[h], x_ = xx_[h_], y_ = yy_[h_];
		bubble(uu[h_]), bubble(vv[h_]);
		if (h + 1 == m || compare_h(h_, hh[h + 1]) != 0)
			ans = max(ans, st[1]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

bulldozer.c: In function 'main':
bulldozer.c:132:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  132 |    if (xx[i] < xx[j] || xx[i] == xx[j] && yy[i] < yy[j])
      |                         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
bulldozer.c:122:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
bulldozer.c:124:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |   scanf("%d%d%d", &xx[i], &yy[i], &ww[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 420 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 424 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 424 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 448 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 476 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 428 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 3 ms 420 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 424 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 448 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 476 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 428 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 3 ms 420 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
33 Correct 1803 ms 40020 KB Output is correct
34 Correct 1718 ms 40216 KB Output is correct
35 Correct 1628 ms 39868 KB Output is correct
36 Correct 1829 ms 40392 KB Output is correct
37 Correct 1840 ms 40224 KB Output is correct
38 Correct 1810 ms 39984 KB Output is correct
39 Correct 1807 ms 40228 KB Output is correct
40 Correct 1807 ms 39992 KB Output is correct
41 Correct 1873 ms 40472 KB Output is correct
42 Correct 1848 ms 40096 KB Output is correct
43 Correct 1663 ms 40116 KB Output is correct
44 Correct 1420 ms 39784 KB Output is correct
45 Correct 1431 ms 39912 KB Output is correct
46 Correct 1370 ms 39840 KB Output is correct
47 Correct 1406 ms 39888 KB Output is correct
48 Correct 1328 ms 39764 KB Output is correct
49 Correct 1420 ms 39860 KB Output is correct
50 Correct 1311 ms 39832 KB Output is correct
51 Correct 1375 ms 39868 KB Output is correct
52 Correct 1320 ms 40000 KB Output is correct
53 Correct 1319 ms 40020 KB Output is correct
54 Correct 1304 ms 40120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 424 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 448 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 476 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 428 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 3 ms 420 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
33 Correct 1803 ms 40020 KB Output is correct
34 Correct 1718 ms 40216 KB Output is correct
35 Correct 1628 ms 39868 KB Output is correct
36 Correct 1829 ms 40392 KB Output is correct
37 Correct 1840 ms 40224 KB Output is correct
38 Correct 1810 ms 39984 KB Output is correct
39 Correct 1807 ms 40228 KB Output is correct
40 Correct 1807 ms 39992 KB Output is correct
41 Correct 1873 ms 40472 KB Output is correct
42 Correct 1848 ms 40096 KB Output is correct
43 Correct 1663 ms 40116 KB Output is correct
44 Correct 1420 ms 39784 KB Output is correct
45 Correct 1431 ms 39912 KB Output is correct
46 Correct 1370 ms 39840 KB Output is correct
47 Correct 1406 ms 39888 KB Output is correct
48 Correct 1328 ms 39764 KB Output is correct
49 Correct 1420 ms 39860 KB Output is correct
50 Correct 1311 ms 39832 KB Output is correct
51 Correct 1375 ms 39868 KB Output is correct
52 Correct 1320 ms 40000 KB Output is correct
53 Correct 1319 ms 40020 KB Output is correct
54 Correct 1304 ms 40120 KB Output is correct
55 Correct 1489 ms 40624 KB Output is correct
56 Correct 1509 ms 40180 KB Output is correct
57 Correct 1465 ms 40352 KB Output is correct
58 Correct 1429 ms 40012 KB Output is correct
59 Correct 1466 ms 40632 KB Output is correct
60 Correct 1462 ms 39984 KB Output is correct
61 Correct 1475 ms 39984 KB Output is correct
62 Correct 1479 ms 40372 KB Output is correct
63 Correct 1555 ms 40020 KB Output is correct
64 Correct 1471 ms 40372 KB Output is correct
65 Correct 1477 ms 40632 KB Output is correct
66 Correct 1492 ms 40304 KB Output is correct
67 Correct 1514 ms 40568 KB Output is correct
68 Correct 1590 ms 40668 KB Output is correct
69 Correct 1614 ms 41148 KB Output is correct
70 Correct 1705 ms 40184 KB Output is correct
71 Correct 1614 ms 40752 KB Output is correct
72 Correct 1630 ms 41012 KB Output is correct
73 Correct 1651 ms 40420 KB Output is correct
74 Correct 1585 ms 40340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 420 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 424 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 3 ms 412 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 424 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 3 ms 448 KB Output is correct
37 Correct 4 ms 468 KB Output is correct
38 Correct 4 ms 476 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 428 KB Output is correct
45 Correct 4 ms 468 KB Output is correct
46 Correct 3 ms 420 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 1803 ms 40020 KB Output is correct
49 Correct 1718 ms 40216 KB Output is correct
50 Correct 1628 ms 39868 KB Output is correct
51 Correct 1829 ms 40392 KB Output is correct
52 Correct 1840 ms 40224 KB Output is correct
53 Correct 1810 ms 39984 KB Output is correct
54 Correct 1807 ms 40228 KB Output is correct
55 Correct 1807 ms 39992 KB Output is correct
56 Correct 1873 ms 40472 KB Output is correct
57 Correct 1848 ms 40096 KB Output is correct
58 Correct 1663 ms 40116 KB Output is correct
59 Correct 1420 ms 39784 KB Output is correct
60 Correct 1431 ms 39912 KB Output is correct
61 Correct 1370 ms 39840 KB Output is correct
62 Correct 1406 ms 39888 KB Output is correct
63 Correct 1328 ms 39764 KB Output is correct
64 Correct 1420 ms 39860 KB Output is correct
65 Correct 1311 ms 39832 KB Output is correct
66 Correct 1375 ms 39868 KB Output is correct
67 Correct 1320 ms 40000 KB Output is correct
68 Correct 1319 ms 40020 KB Output is correct
69 Correct 1304 ms 40120 KB Output is correct
70 Correct 1489 ms 40624 KB Output is correct
71 Correct 1509 ms 40180 KB Output is correct
72 Correct 1465 ms 40352 KB Output is correct
73 Correct 1429 ms 40012 KB Output is correct
74 Correct 1466 ms 40632 KB Output is correct
75 Correct 1462 ms 39984 KB Output is correct
76 Correct 1475 ms 39984 KB Output is correct
77 Correct 1479 ms 40372 KB Output is correct
78 Correct 1555 ms 40020 KB Output is correct
79 Correct 1471 ms 40372 KB Output is correct
80 Correct 1477 ms 40632 KB Output is correct
81 Correct 1492 ms 40304 KB Output is correct
82 Correct 1514 ms 40568 KB Output is correct
83 Correct 1590 ms 40668 KB Output is correct
84 Correct 1614 ms 41148 KB Output is correct
85 Correct 1705 ms 40184 KB Output is correct
86 Correct 1614 ms 40752 KB Output is correct
87 Correct 1630 ms 41012 KB Output is correct
88 Correct 1651 ms 40420 KB Output is correct
89 Correct 1585 ms 40340 KB Output is correct
90 Correct 1840 ms 39988 KB Output is correct
91 Correct 1816 ms 40120 KB Output is correct
92 Correct 1622 ms 40112 KB Output is correct
93 Correct 1563 ms 40160 KB Output is correct
94 Correct 1560 ms 40068 KB Output is correct
95 Correct 1570 ms 40104 KB Output is correct
96 Correct 1503 ms 40692 KB Output is correct
97 Correct 1549 ms 40176 KB Output is correct
98 Correct 1483 ms 39988 KB Output is correct
99 Correct 1558 ms 40460 KB Output is correct
100 Correct 899 ms 40032 KB Output is correct
101 Correct 891 ms 40056 KB Output is correct
102 Correct 828 ms 39888 KB Output is correct
103 Correct 837 ms 39904 KB Output is correct
104 Correct 832 ms 40284 KB Output is correct
105 Correct 1098 ms 40048 KB Output is correct
106 Correct 1097 ms 40004 KB Output is correct
107 Correct 1071 ms 40220 KB Output is correct
108 Correct 1077 ms 40268 KB Output is correct
109 Correct 1098 ms 40616 KB Output is correct
110 Correct 1335 ms 135048 KB Output is correct
111 Correct 1316 ms 135392 KB Output is correct
112 Correct 1284 ms 135412 KB Output is correct
113 Correct 1302 ms 134928 KB Output is correct
114 Correct 1356 ms 135068 KB Output is correct
115 Correct 1293 ms 135008 KB Output is correct
116 Correct 1289 ms 135156 KB Output is correct
117 Correct 1296 ms 135428 KB Output is correct
118 Correct 1304 ms 134880 KB Output is correct
119 Correct 1299 ms 134820 KB Output is correct
120 Correct 0 ms 340 KB Output is correct
121 Correct 0 ms 340 KB Output is correct
122 Correct 1278 ms 39860 KB Output is correct
123 Correct 1280 ms 39856 KB Output is correct
124 Correct 1330 ms 39892 KB Output is correct
125 Correct 1250 ms 39912 KB Output is correct
126 Correct 1247 ms 39980 KB Output is correct
127 Correct 1320 ms 39828 KB Output is correct
128 Correct 1376 ms 39872 KB Output is correct
129 Correct 1371 ms 39968 KB Output is correct
130 Correct 1352 ms 39992 KB Output is correct
131 Correct 1264 ms 39988 KB Output is correct
132 Correct 1377 ms 39868 KB Output is correct
133 Correct 1298 ms 39920 KB Output is correct