Submission #642835

# Submission time Handle Problem Language Result Execution time Memory
642835 2022-09-20T15:33:26 Z rainboy Team Contest (JOI22_team) C
100 / 100
112 ms 7888 KB
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N	150000

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec | 1;
}

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

int *ww;

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 (ww[ii[j]] == ww[i_])
				j++;
			else if (ww[ii[j]] < ww[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], yy[N], zz[N], ii[N], jj[N], kk[N];
	static char deleted[N];
	int n, i, i_, j, j_, k, k_;

	srand_();
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &xx[i], &yy[i], &zz[i]);
	for (i = 0; i < n; i++)
		ii[i] = jj[i] = kk[i] = i;
	ww = xx, sort(ii, 0, n);
	ww = yy, sort(jj, 0, n);
	ww = zz, sort(kk, 0, n);
	i = n - 1, j = n - 1, k = n - 1;
	while (1) {
		i_ = j_ = k_ = -1;
		while (i >= 0 && deleted[i_ = ii[i]])
			i--;
		while (j >= 0 && deleted[j_ = jj[j]])
			j--;
		while (k >= 0 && deleted[k_ = kk[k]])
			k--;
		if (i < 0) {
			printf("-1\n");
			return 0;
		}
		if (yy[i_] >= yy[j_] || zz[i_] >= zz[k_])
			deleted[i_] = 1;
		else if (zz[j_] >= zz[k_] || xx[j_] >= xx[i_])
			deleted[j_] = 1;
		else if (xx[k_] >= xx[i_] || yy[k_] >= yy[j_])
			deleted[k_] = 1;
		else {
			printf("%d\n", xx[i_] + yy[j_] + zz[k_]);
			return 0;
		}
	}
	return 0;
}

Compilation message

team.c: In function 'srand_':
team.c:13:16: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   13 |  X = tv.tv_sec ^ tv.tv_usec | 1;
      |      ~~~~~~~~~~^~~~~~~~~~~~
team.c: In function 'main':
team.c:47:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
team.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d%d%d", &xx[i], &yy[i], &zz[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 292 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 292 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 4 ms 420 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 2 ms 472 KB Output is correct
38 Correct 2 ms 372 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 36 ms 4624 KB Output is correct
12 Correct 23 ms 3276 KB Output is correct
13 Correct 25 ms 3960 KB Output is correct
14 Correct 38 ms 4812 KB Output is correct
15 Correct 32 ms 4768 KB Output is correct
16 Correct 30 ms 4712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 36 ms 4624 KB Output is correct
12 Correct 23 ms 3276 KB Output is correct
13 Correct 25 ms 3960 KB Output is correct
14 Correct 38 ms 4812 KB Output is correct
15 Correct 32 ms 4768 KB Output is correct
16 Correct 30 ms 4712 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 0 ms 296 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 43 ms 4892 KB Output is correct
23 Correct 47 ms 4812 KB Output is correct
24 Correct 32 ms 3712 KB Output is correct
25 Correct 44 ms 5072 KB Output is correct
26 Correct 39 ms 4816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 36 ms 4624 KB Output is correct
12 Correct 23 ms 3276 KB Output is correct
13 Correct 25 ms 3960 KB Output is correct
14 Correct 38 ms 4812 KB Output is correct
15 Correct 32 ms 4768 KB Output is correct
16 Correct 30 ms 4712 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 0 ms 296 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 43 ms 4892 KB Output is correct
23 Correct 47 ms 4812 KB Output is correct
24 Correct 32 ms 3712 KB Output is correct
25 Correct 44 ms 5072 KB Output is correct
26 Correct 39 ms 4816 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 436 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 52 ms 5136 KB Output is correct
35 Correct 52 ms 5044 KB Output is correct
36 Correct 55 ms 5448 KB Output is correct
37 Correct 56 ms 5580 KB Output is correct
38 Correct 39 ms 5404 KB Output is correct
39 Correct 23 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 36 ms 4624 KB Output is correct
12 Correct 23 ms 3276 KB Output is correct
13 Correct 25 ms 3960 KB Output is correct
14 Correct 38 ms 4812 KB Output is correct
15 Correct 32 ms 4768 KB Output is correct
16 Correct 30 ms 4712 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 0 ms 296 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 43 ms 4892 KB Output is correct
23 Correct 47 ms 4812 KB Output is correct
24 Correct 32 ms 3712 KB Output is correct
25 Correct 44 ms 5072 KB Output is correct
26 Correct 39 ms 4816 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 436 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 52 ms 5136 KB Output is correct
35 Correct 52 ms 5044 KB Output is correct
36 Correct 55 ms 5448 KB Output is correct
37 Correct 56 ms 5580 KB Output is correct
38 Correct 39 ms 5404 KB Output is correct
39 Correct 23 ms 3412 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 436 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 432 KB Output is correct
44 Correct 70 ms 5772 KB Output is correct
45 Correct 71 ms 6044 KB Output is correct
46 Correct 71 ms 5900 KB Output is correct
47 Correct 74 ms 5964 KB Output is correct
48 Correct 44 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 292 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 4 ms 420 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 2 ms 472 KB Output is correct
38 Correct 2 ms 372 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 296 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 296 KB Output is correct
50 Correct 36 ms 4624 KB Output is correct
51 Correct 23 ms 3276 KB Output is correct
52 Correct 25 ms 3960 KB Output is correct
53 Correct 38 ms 4812 KB Output is correct
54 Correct 32 ms 4768 KB Output is correct
55 Correct 30 ms 4712 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 0 ms 288 KB Output is correct
58 Correct 0 ms 296 KB Output is correct
59 Correct 0 ms 296 KB Output is correct
60 Correct 1 ms 312 KB Output is correct
61 Correct 43 ms 4892 KB Output is correct
62 Correct 47 ms 4812 KB Output is correct
63 Correct 32 ms 3712 KB Output is correct
64 Correct 44 ms 5072 KB Output is correct
65 Correct 39 ms 4816 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 2 ms 436 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 52 ms 5136 KB Output is correct
74 Correct 52 ms 5044 KB Output is correct
75 Correct 55 ms 5448 KB Output is correct
76 Correct 56 ms 5580 KB Output is correct
77 Correct 39 ms 5404 KB Output is correct
78 Correct 23 ms 3412 KB Output is correct
79 Correct 2 ms 340 KB Output is correct
80 Correct 2 ms 436 KB Output is correct
81 Correct 2 ms 468 KB Output is correct
82 Correct 2 ms 432 KB Output is correct
83 Correct 70 ms 5772 KB Output is correct
84 Correct 71 ms 6044 KB Output is correct
85 Correct 71 ms 5900 KB Output is correct
86 Correct 74 ms 5964 KB Output is correct
87 Correct 44 ms 5868 KB Output is correct
88 Correct 103 ms 7632 KB Output is correct
89 Correct 100 ms 7792 KB Output is correct
90 Correct 100 ms 7828 KB Output is correct
91 Correct 107 ms 7808 KB Output is correct
92 Correct 82 ms 6352 KB Output is correct
93 Correct 97 ms 6692 KB Output is correct
94 Correct 89 ms 6528 KB Output is correct
95 Correct 60 ms 7712 KB Output is correct
96 Correct 112 ms 7756 KB Output is correct
97 Correct 43 ms 7888 KB Output is correct
98 Correct 54 ms 6216 KB Output is correct
99 Correct 59 ms 6412 KB Output is correct