Submission #332959

# Submission time Handle Problem Language Result Execution time Memory
332959 2020-12-04T04:26:08 Z Cantfindme Bali Sculptures (APIO15_sculpture) C++17
37 / 100
835 ms 512 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 = 57;
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 492 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 3 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 7 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 5 ms 492 KB Output is correct
22 Correct 5 ms 492 KB Output is correct
23 Correct 4 ms 492 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 7 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 3 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 3 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 7 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 364 KB Output is correct
21 Correct 5 ms 364 KB Output is correct
22 Correct 5 ms 364 KB Output is correct
23 Correct 4 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 5 ms 364 KB Output is correct
26 Correct 7 ms 364 KB Output is correct
27 Correct 8 ms 364 KB Output is correct
28 Correct 10 ms 364 KB Output is correct
29 Correct 16 ms 364 KB Output is correct
30 Correct 60 ms 364 KB Output is correct
31 Correct 78 ms 492 KB Output is correct
32 Correct 63 ms 492 KB Output is correct
33 Correct 6 ms 492 KB Output is correct
34 Correct 76 ms 492 KB Output is correct
35 Correct 72 ms 492 KB Output is correct
36 Correct 48 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 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 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 7 ms 364 KB Output is correct
15 Correct 10 ms 364 KB Output is correct
16 Correct 16 ms 364 KB Output is correct
17 Correct 46 ms 512 KB Output is correct
18 Correct 77 ms 492 KB Output is correct
19 Correct 63 ms 492 KB Output is correct
20 Correct 6 ms 492 KB Output is correct
21 Correct 78 ms 492 KB Output is correct
22 Correct 70 ms 492 KB Output is correct
23 Correct 50 ms 492 KB Output is correct
24 Correct 88 ms 492 KB Output is correct
25 Correct 92 ms 492 KB Output is correct
26 Correct 259 ms 492 KB Output is correct
27 Correct 599 ms 492 KB Output is correct
28 Correct 831 ms 492 KB Output is correct
29 Correct 648 ms 492 KB Output is correct
30 Correct 21 ms 492 KB Output is correct
31 Correct 728 ms 492 KB Output is correct
32 Correct 835 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 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 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 6 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 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 5 ms 364 KB Output is correct
22 Correct 5 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 5 ms 364 KB Output is correct
26 Correct 6 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 3 ms 364 KB Output is correct
30 Incorrect 3 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 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 7 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Incorrect 3 ms 364 KB Output isn't correct
18 Halted 0 ms 0 KB -