Submission #332988

# Submission time Handle Problem Language Result Execution time Memory
332988 2020-12-04T07:46:53 Z Cantfindme Bali Sculptures (APIO15_sculpture) C++17
100 / 100
123 ms 640 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int maxb = 43;
const int maxn = 2010;
const int INF = INT_MAX/2;

int n,A,B;
int pref[maxn];
int aa[maxn];
int dp1[110][110]; //after x items, j groups: works on not.
int dp2[2010]; //after x items: minimum number of groups 
int curbm;

int cap(int x, int groups) {
	if (dp1[x][groups] != -1) return dp1[x][groups];
	if (groups > B) return 0;
	if (x == n) {
		if (groups >= A and groups <= B) return 1;
		else return 0;
	}
	
	int res = 0;
	for (int i = x; i < n;i++) {
		int sum = pref[i] - (x == 0?0: pref[x - 1]);
		if ((sum & curbm) == 0) res = max(res, cap(i+1,groups+1));
	}
	return dp1[x][groups] = res;
}

int cap2(int x) {
	if (dp2[x] != -1) return dp2[x];
	if (x >= n) return 0;
	
	int res = INF;
	for (int i = x; i < n;i++) {
		int sum = pref[i] - (x == 0?0: pref[x - 1]);
		if ((sum & curbm) == 0) res = min(res, cap2(i+1) + 1);
	}
	
	return dp2[x] = res;
}

int32_t main() {
	FAST
	cin >> n >> A >> B;
	for (int i =0;i<n;i++) cin >> aa[i];
	for (int i =0;i<n;i++) {
		pref[i] = (i==0?0:pref[i-1]) + aa[i];
	}
	
	int ans = (1ll << maxb)-1;
	if (n <= 100) { //a can be > 1
		//Greedy
		for (int b = maxb-1; b >= 0; b--) {
			curbm = (1ll << maxb) - 1;
			curbm ^= (ans ^ (1ll << b));
						
			memset(dp1,-1,sizeof dp1);
			if (cap(0,0)) ans ^= (1ll << b); //If you can limit all groups to have bm that doesn't have (1<<b) then ans can also not have (1<<b)
		}
	} else { //a can only be = 1;
		for (int b = maxb-1; b >= 0; b--) {
			curbm = (1ll << maxb) - 1;
			curbm ^= (ans ^ (1ll << b)); //All of the bits that cannot be on.
			
			memset(dp2,-1,sizeof dp2);
			if (cap2(0) <= B) ans ^= (1ll << b); 
		}
	}
	cout << ans;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 640 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 3 ms 492 KB Output is correct
31 Correct 4 ms 492 KB Output is correct
32 Correct 5 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 5 ms 492 KB Output is correct
35 Correct 6 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 38 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 36 ms 492 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 3 ms 492 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
19 Correct 5 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 5 ms 492 KB Output is correct
22 Correct 4 ms 492 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 26 ms 492 KB Output is correct
28 Correct 36 ms 492 KB Output is correct
29 Correct 36 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 31 ms 620 KB Output is correct
32 Correct 35 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 33 ms 492 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 3 ms 492 KB Output is correct
41 Correct 71 ms 492 KB Output is correct
42 Correct 4 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 5 ms 492 KB Output is correct
45 Correct 36 ms 492 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 5 ms 492 KB Output is correct
48 Correct 5 ms 492 KB Output is correct
49 Correct 12 ms 492 KB Output is correct
50 Correct 27 ms 492 KB Output is correct
51 Correct 36 ms 492 KB Output is correct
52 Correct 35 ms 492 KB Output is correct
53 Correct 2 ms 492 KB Output is correct
54 Correct 31 ms 492 KB Output is correct
55 Correct 35 ms 492 KB Output is correct
56 Correct 2 ms 492 KB Output is correct
57 Correct 4 ms 492 KB Output is correct
58 Correct 8 ms 492 KB Output is correct
59 Correct 12 ms 492 KB Output is correct
60 Correct 10 ms 492 KB Output is correct
61 Correct 1 ms 492 KB Output is correct
62 Correct 14 ms 492 KB Output is correct
63 Correct 14 ms 492 KB Output is correct
64 Correct 30 ms 492 KB Output is correct
65 Correct 2 ms 492 KB Output is correct
66 Correct 2 ms 492 KB Output is correct
67 Correct 4 ms 492 KB Output is correct
68 Correct 8 ms 492 KB Output is correct
69 Correct 11 ms 492 KB Output is correct
70 Correct 10 ms 492 KB Output is correct
71 Correct 1 ms 492 KB Output is correct
72 Correct 13 ms 492 KB Output is correct
73 Correct 13 ms 492 KB Output is correct
74 Correct 13 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 35 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 5 ms 492 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 5 ms 492 KB Output is correct
32 Correct 64 ms 548 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 5 ms 492 KB Output is correct
35 Correct 5 ms 492 KB Output is correct
36 Correct 12 ms 492 KB Output is correct
37 Correct 26 ms 492 KB Output is correct
38 Correct 36 ms 492 KB Output is correct
39 Correct 35 ms 492 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 31 ms 492 KB Output is correct
42 Correct 37 ms 620 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 4 ms 492 KB Output is correct
45 Correct 8 ms 492 KB Output is correct
46 Correct 11 ms 492 KB Output is correct
47 Correct 10 ms 492 KB Output is correct
48 Correct 1 ms 492 KB Output is correct
49 Correct 14 ms 620 KB Output is correct
50 Correct 14 ms 512 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 9 ms 364 KB Output is correct
53 Correct 9 ms 364 KB Output is correct
54 Correct 34 ms 492 KB Output is correct
55 Correct 24 ms 492 KB Output is correct
56 Correct 56 ms 492 KB Output is correct
57 Correct 51 ms 560 KB Output is correct
58 Correct 63 ms 492 KB Output is correct
59 Correct 87 ms 492 KB Output is correct
60 Correct 65 ms 564 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 11 ms 492 KB Output is correct
63 Correct 34 ms 492 KB Output is correct
64 Correct 15 ms 492 KB Output is correct
65 Correct 27 ms 492 KB Output is correct
66 Correct 39 ms 492 KB Output is correct
67 Correct 52 ms 492 KB Output is correct
68 Correct 123 ms 492 KB Output is correct
69 Correct 49 ms 492 KB Output is correct