Submission #590146

# Submission time Handle Problem Language Result Execution time Memory
590146 2022-07-05T14:57:28 Z rainboy Uplifting Excursion (BOI22_vault) C
20 / 100
3620 ms 17984 KB
#include <stdio.h>

#define N	100
#define S	1000000
#define INF	0x3f3f3f3f

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

void upd(int *dp, int a, int k, int c) {
	static int dq[S * 2 + 1], qu[S * 2 + 1];
	int s, r, head, cnt;

	if (a > 0) {
		for (s = 0; s <= S * 2; s++)
			dq[s] = dp[s] == -INF ? -INF : dp[s] - s / a;
		for (r = 0; r < a; r++) {
			head = cnt = 0;
			for (s = r; s <= S * 2; s += a) {
				if (dq[s] != -INF) {
					while (cnt && dq[qu[head + cnt - 1]] < dq[s])
						cnt--;
					qu[head + cnt++] = s;
				}
				dp[s] = cnt == 0 ? -INF : dq[qu[head]] + s / a;
				if (cnt && qu[head] == s - a * k)
					head++, cnt--;
			}
		}
	} else if (a < 0) {
		a = -a;
		for (s = 0; s <= S * 2; s++)
			dq[s] = dp[s] == -INF ? -INF : dp[s] + s / a;
		for (r = 0; r < a; r++) {
			head = cnt = 0;
			for (s = (S * 2 - r) / a * a + r; s >= 0; s -= a) {
				if (dq[s] != -INF) {
					while (cnt && dq[qu[head + cnt - 1]] < dq[s])
						cnt--;
					qu[head + cnt++] = s;
				}
				dp[s] = cnt == 0 ? -INF : dq[qu[head]] - s / a;
				if (cnt && qu[head] == s + a * k)
					head++, cnt--;
			}
		}
	} else {
		if (c <= 0)
			return;
		for (s = 0; s <= S * 2; s++)
			if (dp[s] != -INF)
				dp[s] += k * c;
	}
}

int main() {
	static long long kk[N * 2 + 1];
	static int dp[S * 2 + 1];
	int n, a, s;
	long long s_;

	scanf("%d%lld", &n, &s_);
	for (a = -n; a <= n; a++)
		scanf("%lld", &kk[a + n]);
	if (s_ < -S || s_ > S) {
		printf("impossible\n");
		return 0;
	}
	for (s = 0; s <= S * 2; s++)
		dp[s] = -INF;
	dp[S + 0] = 0;
	for (a = -n; a <= n; a++)
		upd(dp, a, kk[a + n], 1);
	if (dp[S + s_] == -INF)
		printf("impossible\n");
	else
		printf("%d\n", dp[S + s_]);
	return 0;
}

Compilation message

vault.c: In function 'main':
vault.c:61:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d%lld", &n, &s_);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~
vault.c:63:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   scanf("%lld", &kk[a + n]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 15828 KB Output is correct
2 Correct 34 ms 15928 KB Output is correct
3 Correct 15 ms 15940 KB Output is correct
4 Correct 162 ms 15924 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1706 ms 16060 KB Output is correct
7 Correct 1738 ms 15964 KB Output is correct
8 Correct 1637 ms 15924 KB Output is correct
9 Correct 1748 ms 16156 KB Output is correct
10 Correct 1637 ms 15928 KB Output is correct
11 Correct 1649 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 15828 KB Output is correct
2 Correct 34 ms 15928 KB Output is correct
3 Correct 15 ms 15940 KB Output is correct
4 Correct 162 ms 15924 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1706 ms 16060 KB Output is correct
7 Correct 1738 ms 15964 KB Output is correct
8 Correct 1637 ms 15924 KB Output is correct
9 Correct 1748 ms 16156 KB Output is correct
10 Correct 1637 ms 15928 KB Output is correct
11 Correct 1649 ms 15948 KB Output is correct
12 Correct 23 ms 15828 KB Output is correct
13 Correct 37 ms 15924 KB Output is correct
14 Correct 16 ms 15828 KB Output is correct
15 Correct 175 ms 15924 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1688 ms 16064 KB Output is correct
18 Correct 1633 ms 16060 KB Output is correct
19 Correct 1685 ms 16044 KB Output is correct
20 Correct 1697 ms 16188 KB Output is correct
21 Correct 1794 ms 15828 KB Output is correct
22 Correct 1900 ms 15928 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 3222 ms 16888 KB Output is correct
25 Correct 3128 ms 16364 KB Output is correct
26 Correct 3537 ms 17848 KB Output is correct
27 Correct 3620 ms 17984 KB Output is correct
28 Correct 2640 ms 15924 KB Output is correct
29 Correct 2674 ms 15928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 15828 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 15828 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 15828 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 15828 KB Output is correct
2 Correct 34 ms 15928 KB Output is correct
3 Correct 15 ms 15940 KB Output is correct
4 Correct 162 ms 15924 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1706 ms 16060 KB Output is correct
7 Correct 1738 ms 15964 KB Output is correct
8 Correct 1637 ms 15924 KB Output is correct
9 Correct 1748 ms 16156 KB Output is correct
10 Correct 1637 ms 15928 KB Output is correct
11 Correct 1649 ms 15948 KB Output is correct
12 Correct 166 ms 15828 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 15828 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 15828 KB Output is correct
2 Correct 34 ms 15928 KB Output is correct
3 Correct 15 ms 15940 KB Output is correct
4 Correct 162 ms 15924 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1706 ms 16060 KB Output is correct
7 Correct 1738 ms 15964 KB Output is correct
8 Correct 1637 ms 15924 KB Output is correct
9 Correct 1748 ms 16156 KB Output is correct
10 Correct 1637 ms 15928 KB Output is correct
11 Correct 1649 ms 15948 KB Output is correct
12 Correct 23 ms 15828 KB Output is correct
13 Correct 37 ms 15924 KB Output is correct
14 Correct 16 ms 15828 KB Output is correct
15 Correct 175 ms 15924 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1688 ms 16064 KB Output is correct
18 Correct 1633 ms 16060 KB Output is correct
19 Correct 1685 ms 16044 KB Output is correct
20 Correct 1697 ms 16188 KB Output is correct
21 Correct 1794 ms 15828 KB Output is correct
22 Correct 1900 ms 15928 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 3222 ms 16888 KB Output is correct
25 Correct 3128 ms 16364 KB Output is correct
26 Correct 3537 ms 17848 KB Output is correct
27 Correct 3620 ms 17984 KB Output is correct
28 Correct 2640 ms 15924 KB Output is correct
29 Correct 2674 ms 15928 KB Output is correct
30 Correct 166 ms 15828 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 15828 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 15828 KB Output is correct
2 Correct 34 ms 15928 KB Output is correct
3 Correct 15 ms 15940 KB Output is correct
4 Correct 162 ms 15924 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1706 ms 16060 KB Output is correct
7 Correct 1738 ms 15964 KB Output is correct
8 Correct 1637 ms 15924 KB Output is correct
9 Correct 1748 ms 16156 KB Output is correct
10 Correct 1637 ms 15928 KB Output is correct
11 Correct 1649 ms 15948 KB Output is correct
12 Correct 23 ms 15828 KB Output is correct
13 Correct 37 ms 15924 KB Output is correct
14 Correct 16 ms 15828 KB Output is correct
15 Correct 175 ms 15924 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1688 ms 16064 KB Output is correct
18 Correct 1633 ms 16060 KB Output is correct
19 Correct 1685 ms 16044 KB Output is correct
20 Correct 1697 ms 16188 KB Output is correct
21 Correct 1794 ms 15828 KB Output is correct
22 Correct 1900 ms 15928 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 3222 ms 16888 KB Output is correct
25 Correct 3128 ms 16364 KB Output is correct
26 Correct 3537 ms 17848 KB Output is correct
27 Correct 3620 ms 17984 KB Output is correct
28 Correct 2640 ms 15924 KB Output is correct
29 Correct 2674 ms 15928 KB Output is correct
30 Correct 166 ms 15828 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -