Submission #683121

# Submission time Handle Problem Language Result Execution time Memory
683121 2023-01-17T18:30:57 Z rainboy Sparklers (JOI17_sparklers) C
100 / 100
51 ms 5528 KB
#include <stdio.h>

#define N	100000
#define N2	(N * 2 + 1)
#define N4	(N2 * 2)
#define INF	0x3f3f3f3f

long long min(long long a, long long b) { return a < b ? a : b; }

int solve(int *xx, int n, int s, int x) {
	static long long aa[N2], bb[N2], aa_[N4], bb_[N4];
	int na, nb, na_, nb_, r, i, ia, ib, j;
	long long a, b, tmp;

	na = 0;
	aa[na++] = x;
	for (i = s; i > 0; i--)
		aa[na++] = -(xx[i] - xx[i - 1]), aa[na++] = x;
	for (i = 1; i < na; i++)
		aa[i] += aa[i - 1];
	nb = 0;
	bb[nb++] = 0;
	for (i = s; i + 1 < n; i++)
		bb[nb++] = -(xx[i + 1] - xx[i]), bb[nb++] = x;
	for (i = 1; i < nb; i++)
		bb[i] += bb[i - 1];
	for (r = 0; r < 2; r++) {
		i = 0, na_ = 0;
		while (1) {
			aa_[na_++] = aa[i];
			j = i + 1, a = aa[i];
			while (j < na && (r == 0 ? aa[j] <= aa[i] : aa[j] < aa[i]))
				a = min(a, aa[j++]);
			if (j == na)
				break;
			aa_[na_++] = a;
			i = j;
		}
		i = 0, nb_ = 0;
		while (1) {
			bb_[nb_++] = bb[i];
			j = i + 1, b = bb[i];
			while (j < nb && (r == 0 ? bb[j] <= bb[i] : bb[j] < bb[i]))
				b = min(b, bb[j++]);
			if (j == nb)
				break;
			bb_[nb_++] = b;
			i = j;
		}
		if (aa_[0] + bb_[0] < 0)
			return 0;
		ia = ib = 0;
		while (ia + 2 < na_ || ib + 2 < nb_)
			if (ia + 2 < na_ && aa_[ia + 1] + bb_[ib] >= 0)
				ia += 2;
			else if (ib + 2 < nb_ && aa_[ia] + bb_[ib + 1] >= 0)
				ib += 2;
			else
				return 0;
		for (i = 0, j = na - 1; i < j; i++, j--)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
		for (i = 0, j = nb - 1; i < j; i++, j--)
			tmp = bb[i], bb[i] = bb[j], bb[j] = tmp;
	}
	return 1;
}

int main() {
	static int xx[N];
	int n, s, t, i, lower, upper;

	scanf("%d%d%d", &n, &s, &t), s--;
	for (i = 0; i < n; i++)
		scanf("%d", &xx[i]);
	lower = -1, upper = INF;
	while (upper - lower > 1) {
		int v = (lower + upper) / 2;

		if (solve(xx, n, s, min((long long) t * v * 2, INF)))
			upper = v;
		else
			lower = v;
	}
	printf("%d\n", upper);
	return 0;
}

Compilation message

sparklers.c: In function 'main':
sparklers.c:72:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |  scanf("%d%d%d", &n, &s, &t), s--;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.c:74:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%d", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 1 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 292 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 0 ms 288 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 1 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 292 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 0 ms 288 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 296 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 300 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 296 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 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 0 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 1 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 292 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 292 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 0 ms 288 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 292 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 296 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 300 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 296 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 26 ms 3268 KB Output is correct
42 Correct 2 ms 432 KB Output is correct
43 Correct 19 ms 1044 KB Output is correct
44 Correct 39 ms 4772 KB Output is correct
45 Correct 38 ms 4768 KB Output is correct
46 Correct 39 ms 4820 KB Output is correct
47 Correct 51 ms 4684 KB Output is correct
48 Correct 39 ms 4784 KB Output is correct
49 Correct 37 ms 4772 KB Output is correct
50 Correct 38 ms 4676 KB Output is correct
51 Correct 50 ms 4788 KB Output is correct
52 Correct 43 ms 4772 KB Output is correct
53 Correct 40 ms 4776 KB Output is correct
54 Correct 50 ms 4784 KB Output is correct
55 Correct 39 ms 4692 KB Output is correct
56 Correct 37 ms 4692 KB Output is correct
57 Correct 37 ms 4748 KB Output is correct
58 Correct 40 ms 4748 KB Output is correct
59 Correct 43 ms 5528 KB Output is correct
60 Correct 41 ms 4768 KB Output is correct
61 Correct 37 ms 4684 KB Output is correct
62 Correct 37 ms 4692 KB Output is correct
63 Correct 37 ms 4692 KB Output is correct
64 Correct 37 ms 4740 KB Output is correct
65 Correct 41 ms 4784 KB Output is correct
66 Correct 38 ms 4756 KB Output is correct
67 Correct 40 ms 4692 KB Output is correct
68 Correct 38 ms 4692 KB Output is correct
69 Correct 38 ms 4656 KB Output is correct