Submission #32675

# Submission time Handle Problem Language Result Execution time Memory
32675 2017-10-14T02:02:47 Z minimario Bali Sculptures (APIO15_sculpture) C++14
100 / 100
796 ms 2088 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX = 2005;

typedef long long ll;

int y[MAX];
bool in[50];
int dp[MAX], dp2[105][105]; // is it possible to cut 1..n into k parts
ll p[MAX];

// minimum number of parts that we need to cut 1...i into
// in order to have some kth bit off

vector<int> nesc;
bool works(ll x, int k) {
	for (int i : nesc) {
		if (x & (1LL<<i)) { return false; }
	}
	if (x & (1LL<<k)) { return false; }
	return true;
}

int main() {
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	int n, a, b; scanf("%d %d %d", &n, &a, &b);
	for (int i=1; i<=n; i++) {
		scanf("%d", &y[i]);
		p[i] = p[i-1] + (ll)y[i];
	}
	if (a == 1) {
		for (int k=45; k>=0; k--) {
			for (int i=1; i<MAX; i++) { dp[i] = 2005; }
			for (int i=1; i<=n; i++) {
				for (int j=1; j<=i; j++) {
					ll sum = p[i] - p[j-1];
					if (works(sum, k)) {
						dp[i] = min(dp[i], dp[j-1] + 1);
					}
				}
			}
			if (dp[n] <= b) { nesc.push_back(k); }
		}
	}
	else {
		for (int k=45; k>=0; k--) {
			for (int i=0; i<105; i++) { 
				for (int j=0; j<105; j++) {
					dp2[i][j] = false;
				}
			}
			dp2[0][0] = true;
			for (int i=0; i<=n; i++) {
				for (int j=0; j<=i; j++) {
					if (dp2[i][j]) {
						for (int l=i+1; l<=n; l++) {
							ll sum = p[l] - p[i];
							if (works(sum, k)) {
								dp2[l][j+1] = true;
							}
						}
					}
				}
			}
			bool doable = false;
			for (int i=a; i<=b; i++) {
				if (dp2[n][i]) { doable = true; }
			}
			if (doable) { nesc.push_back(k); }
		}
	}
	ll sum = 0;
	for (int i : nesc) { in[i] = true; }
	for (int i=0; i<=45; i++) {
		if (!in[i]) { sum += 1LL<<i; }
	}
	printf("%lld\n", sum);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:28:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, a, b; scanf("%d %d %d", &n, &a, &b);
                                            ^
sculpture.cpp:30:21: 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 0 ms 2088 KB Output is correct
2 Correct 0 ms 2088 KB Output is correct
3 Correct 0 ms 2088 KB Output is correct
4 Correct 0 ms 2088 KB Output is correct
5 Correct 0 ms 2088 KB Output is correct
6 Correct 0 ms 2088 KB Output is correct
7 Correct 0 ms 2088 KB Output is correct
8 Correct 0 ms 2088 KB Output is correct
9 Correct 0 ms 2088 KB Output is correct
10 Correct 0 ms 2088 KB Output is correct
11 Correct 0 ms 2088 KB Output is correct
12 Correct 0 ms 2088 KB Output is correct
13 Correct 0 ms 2088 KB Output is correct
14 Correct 0 ms 2088 KB Output is correct
15 Correct 0 ms 2088 KB Output is correct
16 Correct 0 ms 2088 KB Output is correct
17 Correct 0 ms 2088 KB Output is correct
18 Correct 0 ms 2088 KB Output is correct
19 Correct 0 ms 2088 KB Output is correct
20 Correct 0 ms 2088 KB Output is correct
21 Correct 0 ms 2088 KB Output is correct
22 Correct 0 ms 2088 KB Output is correct
23 Correct 0 ms 2088 KB Output is correct
24 Correct 0 ms 2088 KB Output is correct
25 Correct 0 ms 2088 KB Output is correct
26 Correct 0 ms 2088 KB Output is correct
27 Correct 0 ms 2088 KB Output is correct
28 Correct 0 ms 2088 KB Output is correct
29 Correct 0 ms 2088 KB Output is correct
30 Correct 0 ms 2088 KB Output is correct
31 Correct 0 ms 2088 KB Output is correct
32 Correct 0 ms 2088 KB Output is correct
33 Correct 0 ms 2088 KB Output is correct
34 Correct 0 ms 2088 KB Output is correct
35 Correct 0 ms 2088 KB Output is correct
36 Correct 0 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2088 KB Output is correct
2 Correct 0 ms 2088 KB Output is correct
3 Correct 0 ms 2088 KB Output is correct
4 Correct 0 ms 2088 KB Output is correct
5 Correct 0 ms 2088 KB Output is correct
6 Correct 0 ms 2088 KB Output is correct
7 Correct 0 ms 2088 KB Output is correct
8 Correct 0 ms 2088 KB Output is correct
9 Correct 0 ms 2088 KB Output is correct
10 Correct 0 ms 2088 KB Output is correct
11 Correct 0 ms 2088 KB Output is correct
12 Correct 0 ms 2088 KB Output is correct
13 Correct 0 ms 2088 KB Output is correct
14 Correct 0 ms 2088 KB Output is correct
15 Correct 0 ms 2088 KB Output is correct
16 Correct 0 ms 2088 KB Output is correct
17 Correct 0 ms 2088 KB Output is correct
18 Correct 0 ms 2088 KB Output is correct
19 Correct 0 ms 2088 KB Output is correct
20 Correct 0 ms 2088 KB Output is correct
21 Correct 0 ms 2088 KB Output is correct
22 Correct 0 ms 2088 KB Output is correct
23 Correct 0 ms 2088 KB Output is correct
24 Correct 0 ms 2088 KB Output is correct
25 Correct 0 ms 2088 KB Output is correct
26 Correct 0 ms 2088 KB Output is correct
27 Correct 0 ms 2088 KB Output is correct
28 Correct 0 ms 2088 KB Output is correct
29 Correct 0 ms 2088 KB Output is correct
30 Correct 0 ms 2088 KB Output is correct
31 Correct 0 ms 2088 KB Output is correct
32 Correct 0 ms 2088 KB Output is correct
33 Correct 0 ms 2088 KB Output is correct
34 Correct 0 ms 2088 KB Output is correct
35 Correct 0 ms 2088 KB Output is correct
36 Correct 0 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2088 KB Output is correct
2 Correct 0 ms 2088 KB Output is correct
3 Correct 0 ms 2088 KB Output is correct
4 Correct 0 ms 2088 KB Output is correct
5 Correct 0 ms 2088 KB Output is correct
6 Correct 0 ms 2088 KB Output is correct
7 Correct 0 ms 2088 KB Output is correct
8 Correct 0 ms 2088 KB Output is correct
9 Correct 0 ms 2088 KB Output is correct
10 Correct 0 ms 2088 KB Output is correct
11 Correct 0 ms 2088 KB Output is correct
12 Correct 0 ms 2088 KB Output is correct
13 Correct 0 ms 2088 KB Output is correct
14 Correct 0 ms 2088 KB Output is correct
15 Correct 0 ms 2088 KB Output is correct
16 Correct 0 ms 2088 KB Output is correct
17 Correct 0 ms 2088 KB Output is correct
18 Correct 0 ms 2088 KB Output is correct
19 Correct 0 ms 2088 KB Output is correct
20 Correct 0 ms 2088 KB Output is correct
21 Correct 0 ms 2088 KB Output is correct
22 Correct 0 ms 2088 KB Output is correct
23 Correct 0 ms 2088 KB Output is correct
24 Correct 0 ms 2088 KB Output is correct
25 Correct 0 ms 2088 KB Output is correct
26 Correct 3 ms 2088 KB Output is correct
27 Correct 3 ms 2088 KB Output is correct
28 Correct 3 ms 2088 KB Output is correct
29 Correct 3 ms 2088 KB Output is correct
30 Correct 3 ms 2088 KB Output is correct
31 Correct 3 ms 2088 KB Output is correct
32 Correct 6 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2088 KB Output is correct
2 Correct 0 ms 2088 KB Output is correct
3 Correct 0 ms 2088 KB Output is correct
4 Correct 0 ms 2088 KB Output is correct
5 Correct 0 ms 2088 KB Output is correct
6 Correct 0 ms 2088 KB Output is correct
7 Correct 0 ms 2088 KB Output is correct
8 Correct 0 ms 2088 KB Output is correct
9 Correct 0 ms 2088 KB Output is correct
10 Correct 0 ms 2088 KB Output is correct
11 Correct 0 ms 2088 KB Output is correct
12 Correct 0 ms 2088 KB Output is correct
13 Correct 0 ms 2088 KB Output is correct
14 Correct 0 ms 2088 KB Output is correct
15 Correct 0 ms 2088 KB Output is correct
16 Correct 0 ms 2088 KB Output is correct
17 Correct 0 ms 2088 KB Output is correct
18 Correct 0 ms 2088 KB Output is correct
19 Correct 0 ms 2088 KB Output is correct
20 Correct 0 ms 2088 KB Output is correct
21 Correct 0 ms 2088 KB Output is correct
22 Correct 0 ms 2088 KB Output is correct
23 Correct 0 ms 2088 KB Output is correct
24 Correct 0 ms 2088 KB Output is correct
25 Correct 0 ms 2088 KB Output is correct
26 Correct 0 ms 2088 KB Output is correct
27 Correct 0 ms 2088 KB Output is correct
28 Correct 0 ms 2088 KB Output is correct
29 Correct 0 ms 2088 KB Output is correct
30 Correct 0 ms 2088 KB Output is correct
31 Correct 0 ms 2088 KB Output is correct
32 Correct 0 ms 2088 KB Output is correct
33 Correct 0 ms 2088 KB Output is correct
34 Correct 0 ms 2088 KB Output is correct
35 Correct 0 ms 2088 KB Output is correct
36 Correct 0 ms 2088 KB Output is correct
37 Correct 0 ms 2088 KB Output is correct
38 Correct 0 ms 2088 KB Output is correct
39 Correct 0 ms 2088 KB Output is correct
40 Correct 0 ms 2088 KB Output is correct
41 Correct 0 ms 2088 KB Output is correct
42 Correct 0 ms 2088 KB Output is correct
43 Correct 0 ms 2088 KB Output is correct
44 Correct 0 ms 2088 KB Output is correct
45 Correct 0 ms 2088 KB Output is correct
46 Correct 0 ms 2088 KB Output is correct
47 Correct 0 ms 2088 KB Output is correct
48 Correct 3 ms 2088 KB Output is correct
49 Correct 3 ms 2088 KB Output is correct
50 Correct 3 ms 2088 KB Output is correct
51 Correct 6 ms 2088 KB Output is correct
52 Correct 3 ms 2088 KB Output is correct
53 Correct 9 ms 2088 KB Output is correct
54 Correct 3 ms 2088 KB Output is correct
55 Correct 6 ms 2088 KB Output is correct
56 Correct 0 ms 2088 KB Output is correct
57 Correct 0 ms 2088 KB Output is correct
58 Correct 3 ms 2088 KB Output is correct
59 Correct 3 ms 2088 KB Output is correct
60 Correct 3 ms 2088 KB Output is correct
61 Correct 3 ms 2088 KB Output is correct
62 Correct 3 ms 2088 KB Output is correct
63 Correct 3 ms 2088 KB Output is correct
64 Correct 133 ms 2088 KB Output is correct
65 Correct 3 ms 2088 KB Output is correct
66 Correct 6 ms 2088 KB Output is correct
67 Correct 16 ms 2088 KB Output is correct
68 Correct 19 ms 2088 KB Output is correct
69 Correct 23 ms 2088 KB Output is correct
70 Correct 23 ms 2088 KB Output is correct
71 Correct 26 ms 2088 KB Output is correct
72 Correct 29 ms 2088 KB Output is correct
73 Correct 36 ms 2088 KB Output is correct
74 Correct 33 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2088 KB Output is correct
2 Correct 0 ms 2088 KB Output is correct
3 Correct 0 ms 2088 KB Output is correct
4 Correct 0 ms 2088 KB Output is correct
5 Correct 0 ms 2088 KB Output is correct
6 Correct 0 ms 2088 KB Output is correct
7 Correct 0 ms 2088 KB Output is correct
8 Correct 0 ms 2088 KB Output is correct
9 Correct 0 ms 2088 KB Output is correct
10 Correct 0 ms 2088 KB Output is correct
11 Correct 0 ms 2088 KB Output is correct
12 Correct 0 ms 2088 KB Output is correct
13 Correct 0 ms 2088 KB Output is correct
14 Correct 0 ms 2088 KB Output is correct
15 Correct 0 ms 2088 KB Output is correct
16 Correct 0 ms 2088 KB Output is correct
17 Correct 0 ms 2088 KB Output is correct
18 Correct 0 ms 2088 KB Output is correct
19 Correct 0 ms 2088 KB Output is correct
20 Correct 0 ms 2088 KB Output is correct
21 Correct 0 ms 2088 KB Output is correct
22 Correct 0 ms 2088 KB Output is correct
23 Correct 0 ms 2088 KB Output is correct
24 Correct 0 ms 2088 KB Output is correct
25 Correct 0 ms 2088 KB Output is correct
26 Correct 0 ms 2088 KB Output is correct
27 Correct 0 ms 2088 KB Output is correct
28 Correct 0 ms 2088 KB Output is correct
29 Correct 0 ms 2088 KB Output is correct
30 Correct 0 ms 2088 KB Output is correct
31 Correct 0 ms 2088 KB Output is correct
32 Correct 0 ms 2088 KB Output is correct
33 Correct 0 ms 2088 KB Output is correct
34 Correct 0 ms 2088 KB Output is correct
35 Correct 0 ms 2088 KB Output is correct
36 Correct 3 ms 2088 KB Output is correct
37 Correct 3 ms 2088 KB Output is correct
38 Correct 6 ms 2088 KB Output is correct
39 Correct 6 ms 2088 KB Output is correct
40 Correct 3 ms 2088 KB Output is correct
41 Correct 6 ms 2088 KB Output is correct
42 Correct 6 ms 2088 KB Output is correct
43 Correct 0 ms 2088 KB Output is correct
44 Correct 0 ms 2088 KB Output is correct
45 Correct 0 ms 2088 KB Output is correct
46 Correct 3 ms 2088 KB Output is correct
47 Correct 3 ms 2088 KB Output is correct
48 Correct 3 ms 2088 KB Output is correct
49 Correct 3 ms 2088 KB Output is correct
50 Correct 3 ms 2088 KB Output is correct
51 Correct 3 ms 2088 KB Output is correct
52 Correct 103 ms 2088 KB Output is correct
53 Correct 139 ms 2088 KB Output is correct
54 Correct 219 ms 2088 KB Output is correct
55 Correct 229 ms 2088 KB Output is correct
56 Correct 779 ms 2088 KB Output is correct
57 Correct 776 ms 2088 KB Output is correct
58 Correct 679 ms 2088 KB Output is correct
59 Correct 746 ms 2088 KB Output is correct
60 Correct 699 ms 2088 KB Output is correct
61 Correct 3 ms 2088 KB Output is correct
62 Correct 136 ms 2088 KB Output is correct
63 Correct 233 ms 2088 KB Output is correct
64 Correct 213 ms 2088 KB Output is correct
65 Correct 416 ms 2088 KB Output is correct
66 Correct 613 ms 2088 KB Output is correct
67 Correct 653 ms 2088 KB Output is correct
68 Correct 796 ms 2088 KB Output is correct
69 Correct 719 ms 2088 KB Output is correct