Submission #332958

# Submission time Handle Problem Language Result Execution time Memory
332958 2020-12-04T04:25:13 Z Cantfindme Bali Sculptures (APIO15_sculpture) C++17
37 / 100
727 ms 620 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 = 50;
const int maxn = 2010;
int n,A,B;
int pref[maxn];
int aa[maxn];
int dp1[110][110];
int dp2[2010];
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]);
		
		bool works = true;
		for (int b = 0; b < maxb and works; b++) {
			if (sum & (1 << b) and !(curbm & (1 << b))) works = false;
		}
		if (works) res = max(res, cap(i+1,groups+1));
	}
	return dp1[x][groups] = res;
}

int32_t main() {
	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 = ans ^ (1ll << b);
			//cout << "HI: " << b << " " << curbm << "\n";
			memset(dp1,-1,sizeof dp1);
			if (cap(0,0)) ans = curbm; //If you can limit all groups to have bm that doesn't have (1<<b) then ans can also not have (1<<b)
			//cout << "NEW: " << curbm << " " << ans << "\n\n";
		}
	} else { //a can only be = 1;
		
	}
	cout << ans;
}

# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 5 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 3 ms 492 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 4 ms 364 KB Output is correct
22 Correct 4 ms 492 KB Output is correct
23 Correct 4 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 4 ms 364 KB Output is correct
26 Correct 5 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 2 ms 364 KB Output is correct
30 Incorrect 2 ms 364 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 5 ms 492 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 3 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 47 ms 392 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 6 ms 492 KB Output is correct
26 Correct 5 ms 492 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 8 ms 492 KB Output is correct
29 Correct 13 ms 492 KB Output is correct
30 Correct 35 ms 492 KB Output is correct
31 Correct 62 ms 492 KB Output is correct
32 Correct 48 ms 492 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 59 ms 492 KB Output is correct
35 Correct 57 ms 492 KB Output is correct
36 Correct 38 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 5 ms 492 KB Output is correct
14 Correct 7 ms 492 KB Output is correct
15 Correct 8 ms 492 KB Output is correct
16 Correct 12 ms 492 KB Output is correct
17 Correct 35 ms 492 KB Output is correct
18 Correct 58 ms 492 KB Output is correct
19 Correct 48 ms 492 KB Output is correct
20 Correct 5 ms 492 KB Output is correct
21 Correct 58 ms 492 KB Output is correct
22 Correct 57 ms 492 KB Output is correct
23 Correct 38 ms 492 KB Output is correct
24 Correct 66 ms 492 KB Output is correct
25 Correct 78 ms 492 KB Output is correct
26 Correct 214 ms 492 KB Output is correct
27 Correct 505 ms 492 KB Output is correct
28 Correct 701 ms 620 KB Output is correct
29 Correct 479 ms 512 KB Output is correct
30 Correct 17 ms 492 KB Output is correct
31 Correct 635 ms 492 KB Output is correct
32 Correct 727 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 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 1 ms 364 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 4 ms 620 KB Output is correct
13 Correct 5 ms 492 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 3 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 492 KB Output is correct
23 Correct 4 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 4 ms 492 KB Output is correct
26 Correct 5 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 2 ms 492 KB Output is correct
30 Incorrect 3 ms 492 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 5 ms 492 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Incorrect 4 ms 380 KB Output isn't correct
18 Halted 0 ms 0 KB -