Submission #707725

# Submission time Handle Problem Language Result Execution time Memory
707725 2023-03-09T21:13:25 Z rainboy Just Long Neckties (JOI20_ho_t1) C
100 / 100
133 ms 11576 KB
#include <stdio.h>

#define N	200000

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

unsigned int X = 12345;

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

int *xx;

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 (xx[ii[j]] == xx[i_])
				j++;
			else if (xx[ii[j]] < xx[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 aa[N + 1], bb[N], ii[N + 1], jj[N], pp[N + 1], qq[N + 1], ans[N + 1];
	int n, i, j;

	scanf("%d", &n);
	for (i = 0; i <= n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j < n; j++)
		scanf("%d", &bb[j]);
	for (i = 0; i <= n; i++)
		ii[i] = i;
	xx = aa, sort(ii, 0, n + 1);
	for (j = 0; j < n; j++)
		jj[j] = j;
	xx = bb, sort(jj, 0, n);
	pp[0] = 0;
	for (i = 0; i < n; i++)
		pp[i + 1] = max(pp[i], aa[ii[i]] - bb[jj[i]]);
	qq[n] = 0;
	for (j = n - 1; j >= 0; j--)
		qq[j] = max(qq[j + 1], aa[ii[j + 1]] - bb[jj[j]]);
	for (i = 0; i <= n; i++)
		ans[ii[i]] = max(pp[i], qq[i]);
	for (i = 0; i <= n; i++)
		printf("%d ", ans[i]);
	printf("\n");
	return 0;
}

Compilation message

ho_t1.c: In function 'main':
ho_t1.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
ho_t1.c:41:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
ho_t1.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d", &bb[j]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 288 KB Output is correct
5 Correct 1 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 0 ms 284 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 288 KB Output is correct
5 Correct 1 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 0 ms 284 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 292 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 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 2 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 304 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 0 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 288 KB Output is correct
5 Correct 1 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 0 ms 284 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 292 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 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 2 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 304 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 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 113 ms 10676 KB Output is correct
34 Correct 133 ms 11060 KB Output is correct
35 Correct 118 ms 10780 KB Output is correct
36 Correct 120 ms 11204 KB Output is correct
37 Correct 121 ms 11576 KB Output is correct
38 Correct 127 ms 11412 KB Output is correct
39 Correct 127 ms 10436 KB Output is correct
40 Correct 116 ms 10360 KB Output is correct
41 Correct 122 ms 10468 KB Output is correct
42 Correct 124 ms 10504 KB Output is correct
43 Correct 118 ms 10408 KB Output is correct
44 Correct 125 ms 10072 KB Output is correct
45 Correct 129 ms 10228 KB Output is correct
46 Correct 119 ms 10060 KB Output is correct
47 Correct 81 ms 10160 KB Output is correct
48 Correct 80 ms 10140 KB Output is correct
49 Correct 121 ms 10724 KB Output is correct
50 Correct 126 ms 10712 KB Output is correct
51 Correct 123 ms 10760 KB Output is correct
52 Correct 125 ms 10688 KB Output is correct
53 Correct 126 ms 10696 KB Output is correct