Submission #212686

# Submission time Handle Problem Language Result Execution time Memory
212686 2020-03-24T05:37:50 Z spdskatr Bali Sculptures (APIO15_sculpture) C++14
100 / 100
107 ms 540 KB
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;
typedef long long ll;

int N, A, B, y[2005], dp[105][105];
int seen[2005], dists[2005];
ll ps[2005];
queue<int> bfs;

int solve(ll mask, int bit) {
	if (N <= 100) {
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		for (int i = 1; i <= N; i++) {
			for (int k = 1; k <= B; k++) {
				for (int j = 1; j <= i; j++) {
					ll val = ps[i] - ps[j-1];
					if (((val|mask)^mask) <= ((1LL << bit) - 1)) {
						dp[i][k] |= dp[j-1][k-1];
					}
				}
			}
		}
		for (int k = A; k <= B; k++) if (dp[N][k]) return 1;
		return 0;
	} else {
		memset(seen, 0, sizeof(seen));
		seen[0] = 1;
		bfs.push(0);
		while (!bfs.empty()) {
			int i = bfs.front(); bfs.pop();
			if (dists[i] == B) continue;
			for (int j = i+1; j <= N; j++) {
				ll val = ps[j] - ps[i];
				if (!seen[j] && ((val|mask) ^ mask) <= ((1LL << bit) - 1)) {
					seen[j] = 1;
					dists[j] = dists[i] + 1;
					bfs.push(j);
				}
			}
		}
		return seen[N];
	}
}

int main() {
	scanf("%d %d %d", &N, &A, &B);
	for (int i = 1; i <= N; i++) {
		scanf("%d", y+i);
		ps[i] = ps[i-1] + y[i];
	}
	ll res = 0;
	for (int b = 42; b >= 0; b--) {
		if (!solve(res, b)) res |= (1LL << b);
	}
	printf("%lld\n", res);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &N, &A, &B);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", y+i);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 404 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 7 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 304 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 7 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 11 ms 384 KB Output is correct
27 Correct 24 ms 384 KB Output is correct
28 Correct 49 ms 384 KB Output is correct
29 Correct 47 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 25 ms 384 KB Output is correct
32 Correct 37 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 7 ms 384 KB Output is correct
41 Correct 6 ms 384 KB Output is correct
42 Correct 7 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 6 ms 384 KB Output is correct
45 Correct 6 ms 384 KB Output is correct
46 Correct 6 ms 384 KB Output is correct
47 Correct 7 ms 384 KB Output is correct
48 Correct 7 ms 384 KB Output is correct
49 Correct 11 ms 384 KB Output is correct
50 Correct 24 ms 384 KB Output is correct
51 Correct 48 ms 504 KB Output is correct
52 Correct 49 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 26 ms 384 KB Output is correct
55 Correct 38 ms 384 KB Output is correct
56 Correct 7 ms 384 KB Output is correct
57 Correct 10 ms 384 KB Output is correct
58 Correct 21 ms 384 KB Output is correct
59 Correct 39 ms 384 KB Output is correct
60 Correct 41 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 42 ms 384 KB Output is correct
63 Correct 42 ms 384 KB Output is correct
64 Correct 39 ms 384 KB Output is correct
65 Correct 7 ms 384 KB Output is correct
66 Correct 6 ms 384 KB Output is correct
67 Correct 10 ms 384 KB Output is correct
68 Correct 23 ms 504 KB Output is correct
69 Correct 41 ms 384 KB Output is correct
70 Correct 41 ms 384 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 41 ms 384 KB Output is correct
73 Correct 32 ms 384 KB Output is correct
74 Correct 29 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 7 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 11 ms 384 KB Output is correct
37 Correct 26 ms 384 KB Output is correct
38 Correct 49 ms 384 KB Output is correct
39 Correct 50 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 25 ms 384 KB Output is correct
42 Correct 37 ms 384 KB Output is correct
43 Correct 6 ms 384 KB Output is correct
44 Correct 10 ms 384 KB Output is correct
45 Correct 21 ms 384 KB Output is correct
46 Correct 40 ms 384 KB Output is correct
47 Correct 40 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 41 ms 384 KB Output is correct
50 Correct 40 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 13 ms 384 KB Output is correct
53 Correct 9 ms 384 KB Output is correct
54 Correct 32 ms 384 KB Output is correct
55 Correct 22 ms 384 KB Output is correct
56 Correct 38 ms 384 KB Output is correct
57 Correct 32 ms 384 KB Output is correct
58 Correct 49 ms 384 KB Output is correct
59 Correct 76 ms 504 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 256 KB Output is correct
62 Correct 9 ms 384 KB Output is correct
63 Correct 32 ms 384 KB Output is correct
64 Correct 12 ms 384 KB Output is correct
65 Correct 19 ms 384 KB Output is correct
66 Correct 26 ms 384 KB Output is correct
67 Correct 5 ms 384 KB Output is correct
68 Correct 107 ms 384 KB Output is correct
69 Correct 34 ms 540 KB Output is correct