답안 #708017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708017 2023-03-10T19:25:59 Z rainboy Snowball (JOI21_ho_t2) C
100 / 100
117 ms 13716 KB
#include <stdio.h>

#define N	200000
#define Q	200000

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

int main() {
	static long long xx[N], aa[Q + 1], bb[Q + 1], ans[N];
	int n, q, h, i, lower, upper;
	long long d, x;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%lld", &xx[i]);
	x = 0;
	for (h = 0; h < q; h++) {
		scanf("%lld", &d);
		x += d;
		aa[h + 1] = max(aa[h], -x), bb[h + 1] = max(bb[h], x);
	}
	ans[0] += aa[q], ans[n - 1] += bb[q];
	for (i = 1; i < n; i++) {
		x = xx[i] - xx[i - 1];
		lower = -1, upper = q + 1;
		while (upper - lower > 1) {
			h = (lower + upper) / 2;
			if (aa[h] + bb[h] <= x)
				lower = h;
			else
				upper = h;
		}
		h = lower;
		if (h == q)
			ans[i - 1] += bb[h], ans[i] += aa[h];
		else if (aa[h] < aa[h + 1])
			ans[i - 1] += bb[h], ans[i] += x - bb[h];
		else
			ans[i - 1] += x - aa[h], ans[i] += aa[h];
	}
	for (i = 0; i < n; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%lld", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~
Main.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%lld", &d);
      |   ^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 39 ms 5528 KB Output is correct
21 Correct 31 ms 5348 KB Output is correct
22 Correct 29 ms 5112 KB Output is correct
23 Correct 28 ms 4980 KB Output is correct
24 Correct 34 ms 5428 KB Output is correct
25 Correct 111 ms 11868 KB Output is correct
26 Correct 117 ms 11700 KB Output is correct
27 Correct 106 ms 11344 KB Output is correct
28 Correct 112 ms 11596 KB Output is correct
29 Correct 114 ms 11056 KB Output is correct
30 Correct 101 ms 10440 KB Output is correct
31 Correct 85 ms 9868 KB Output is correct
32 Correct 81 ms 10072 KB Output is correct
33 Correct 10 ms 1492 KB Output is correct
34 Correct 114 ms 12236 KB Output is correct
35 Correct 105 ms 11552 KB Output is correct
36 Correct 113 ms 11724 KB Output is correct
37 Correct 107 ms 11596 KB Output is correct
38 Correct 109 ms 11392 KB Output is correct
39 Correct 109 ms 11604 KB Output is correct
40 Correct 93 ms 11560 KB Output is correct
41 Correct 34 ms 6092 KB Output is correct
42 Correct 77 ms 9960 KB Output is correct
43 Correct 98 ms 13260 KB Output is correct
44 Correct 32 ms 6032 KB Output is correct
45 Correct 90 ms 11468 KB Output is correct
46 Correct 113 ms 13364 KB Output is correct
47 Correct 101 ms 13592 KB Output is correct
48 Correct 106 ms 13716 KB Output is correct