Submission #377701

# Submission time Handle Problem Language Result Execution time Memory
377701 2021-03-14T19:16:10 Z rainboy Bali Sculptures (APIO15_sculpture) C
100 / 100
89 ms 748 KB
#include <stdio.h>
#include <string.h>

#define N	2000
#define H	40
#define INF	0x3f3f3f3f

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

int solve(int *aa, int n, int l, int r, long long x) {
	static int dp[N + 1], dq[N + 1][N + 1];
	int i, j, k;
	long long sum;

	if (l == 1) {
		memset(dp, 0x3f, (n + 1) * sizeof *dp);
		dp[0] = 0;
		for (i = 0; i < n; i++)
			if (dp[i] != INF) {
				sum = 0;
				for (j = i + 1; j <= n; j++) {
					sum += aa[j - 1];
					if ((x | sum) == x)
						dp[j] = min(dp[j], dp[i] + 1);
				}
			}
		return dp[n] <= r;
	} else {
		for (i = 0; i <= n; i++)
			memset(dq[i], 0, (n + 1) * sizeof *dq[i]);
		dq[0][0] = 1;
		for (i = 0; i < n; i++)
			for (k = 0; k < n; k++)
				if (dq[i][k]) {
					sum = 0;
					for (j = i + 1; j <= n; j++) {
						sum += aa[j - 1];
						if ((x | sum) == x)
							dq[j][k + 1] = 1;
					}
				}
		for (k = l; k <= r; k++)
			if (dq[n][k])
				return 1;
		return 0;
	}
}

int main() {
	static int aa[N];
	int n, l, r, h, i;
	long long ans;

	scanf("%d%d%d", &n, &l, &r);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	ans = (1LL << H + 1) - 1;
	for (h = H; h >= 0; h--)
		if (solve(aa, n, l, r, ans ^ 1LL << h))
			ans ^= 1LL << h;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

sculpture.c: In function 'main':
sculpture.c:57:13: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   57 |  ans = (1LL << H + 1) - 1;
      |             ^~
sculpture.c:54:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   54 |  scanf("%d%d%d", &n, &l, &r);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.c:56:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   56 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 0 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 0 ms 364 KB Output is correct
34 Correct 0 ms 364 KB Output is correct
35 Correct 0 ms 364 KB Output is correct
36 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 0 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 388 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 83 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 0 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 83 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 0 ms 364 KB Output is correct
38 Correct 0 ms 364 KB Output is correct
39 Correct 40 ms 364 KB Output is correct
40 Correct 82 ms 364 KB Output is correct
41 Correct 84 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 8 ms 748 KB Output is correct
65 Correct 1 ms 492 KB Output is correct
66 Correct 2 ms 620 KB Output is correct
67 Correct 3 ms 620 KB Output is correct
68 Correct 3 ms 748 KB Output is correct
69 Correct 4 ms 748 KB Output is correct
70 Correct 4 ms 748 KB Output is correct
71 Correct 4 ms 748 KB Output is correct
72 Correct 6 ms 748 KB Output is correct
73 Correct 5 ms 748 KB Output is correct
74 Correct 7 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 0 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 0 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 6 ms 364 KB Output is correct
53 Correct 4 ms 364 KB Output is correct
54 Correct 23 ms 364 KB Output is correct
55 Correct 15 ms 364 KB Output is correct
56 Correct 39 ms 364 KB Output is correct
57 Correct 25 ms 364 KB Output is correct
58 Correct 40 ms 364 KB Output is correct
59 Correct 57 ms 364 KB Output is correct
60 Correct 38 ms 364 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 5 ms 364 KB Output is correct
63 Correct 24 ms 364 KB Output is correct
64 Correct 7 ms 364 KB Output is correct
65 Correct 13 ms 364 KB Output is correct
66 Correct 19 ms 364 KB Output is correct
67 Correct 26 ms 364 KB Output is correct
68 Correct 89 ms 492 KB Output is correct
69 Correct 25 ms 364 KB Output is correct