Submission #872796

# Submission time Handle Problem Language Result Execution time Memory
872796 2023-11-13T20:18:57 Z rainboy Lasers (NOI19_lasers) C
100 / 100
107 ms 13328 KB
#include <stdio.h>

#define M	500000

unsigned int X = 12345;

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

int ll[M], rr[M];

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)
			if (ll[hh[j]] == ll[h])
				j++;
			else if (ll[hh[j]] < ll[h]) {
				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 ww[M], hh[M];
	int n, m, k, l, h, h_, i, wl, wr, r, ans;

	scanf("%d%d", &l, &n);
	m = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &k);
		wr = 0;
		for (h = 0; h < k; h++) {
			scanf("%d", &ww[h]);
			wr += ww[h];
		}
		wl = 0;
		for (h = 0; h < k; h++) {
			wl += ww[h];
			if (l - wr < wl)
				ll[m] = l - wr, rr[m] = wl, m++;
			wr -= ww[h];
		}
	}
	for (h = 0; h < m; h++)
		hh[h] = h;
	sort(hh, 0, m);
	ans = 0;
	for (h = 0, r = 0; h < m; h++) {
		h_ = hh[h];
		if (r < ll[h_])
			ans += rr[h_] - ll[h_], r = rr[h_];
		else if (r < rr[h_])
			ans += rr[h_] - r, r = rr[h_];
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

lasers.c: In function 'main':
lasers.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d%d", &l, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~
lasers.c:39:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%d", &k);
      |   ^~~~~~~~~~~~~~~
lasers.c:42:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |    scanf("%d", &ww[h]);
      |    ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 74 ms 13328 KB Output is correct
13 Correct 0 ms 2552 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6744 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 106 ms 13148 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 0 ms 2476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7772 KB Output is correct
2 Correct 7 ms 6748 KB Output is correct
3 Correct 8 ms 6680 KB Output is correct
4 Correct 35 ms 7780 KB Output is correct
5 Correct 16 ms 7256 KB Output is correct
6 Correct 29 ms 7580 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 34 ms 7688 KB Output is correct
9 Correct 23 ms 7472 KB Output is correct
10 Correct 40 ms 7956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6572 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6568 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7772 KB Output is correct
2 Correct 7 ms 6748 KB Output is correct
3 Correct 8 ms 6680 KB Output is correct
4 Correct 35 ms 7780 KB Output is correct
5 Correct 16 ms 7256 KB Output is correct
6 Correct 29 ms 7580 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 34 ms 7688 KB Output is correct
9 Correct 23 ms 7472 KB Output is correct
10 Correct 40 ms 7956 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6572 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6568 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 103 ms 11644 KB Output is correct
22 Correct 17 ms 7260 KB Output is correct
23 Correct 11 ms 7004 KB Output is correct
24 Correct 46 ms 8380 KB Output is correct
25 Correct 103 ms 11740 KB Output is correct
26 Correct 37 ms 8276 KB Output is correct
27 Correct 14 ms 7260 KB Output is correct
28 Correct 102 ms 11624 KB Output is correct
29 Correct 104 ms 11840 KB Output is correct
30 Correct 39 ms 7764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 74 ms 13328 KB Output is correct
13 Correct 0 ms 2552 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6744 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 106 ms 13148 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 0 ms 2476 KB Output is correct
21 Correct 33 ms 7772 KB Output is correct
22 Correct 7 ms 6748 KB Output is correct
23 Correct 8 ms 6680 KB Output is correct
24 Correct 35 ms 7780 KB Output is correct
25 Correct 16 ms 7256 KB Output is correct
26 Correct 29 ms 7580 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 34 ms 7688 KB Output is correct
29 Correct 23 ms 7472 KB Output is correct
30 Correct 40 ms 7956 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6572 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6568 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 1 ms 6748 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 103 ms 11644 KB Output is correct
42 Correct 17 ms 7260 KB Output is correct
43 Correct 11 ms 7004 KB Output is correct
44 Correct 46 ms 8380 KB Output is correct
45 Correct 103 ms 11740 KB Output is correct
46 Correct 37 ms 8276 KB Output is correct
47 Correct 14 ms 7260 KB Output is correct
48 Correct 102 ms 11624 KB Output is correct
49 Correct 104 ms 11840 KB Output is correct
50 Correct 39 ms 7764 KB Output is correct
51 Correct 18 ms 7320 KB Output is correct
52 Correct 107 ms 13136 KB Output is correct
53 Correct 104 ms 13012 KB Output is correct
54 Correct 30 ms 8064 KB Output is correct
55 Correct 63 ms 10376 KB Output is correct
56 Correct 37 ms 8528 KB Output is correct
57 Correct 40 ms 9040 KB Output is correct
58 Correct 107 ms 12996 KB Output is correct
59 Correct 30 ms 8324 KB Output is correct
60 Correct 43 ms 9248 KB Output is correct