답안 #332987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332987 2020-12-04T07:38:14 Z Cantfindme Bali Sculptures (APIO15_sculpture) C++17
71 / 100
1000 ms 748 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]);
		
		bool works = true;
		for (int b = 0; b < maxb and works; b++) {
			if (sum & (1ll << b) and !(curbm & (1ll << b))) works = false;
		}
		if (works) 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]);
		
		bool works = true;
		for (int b = 0; b < maxb and works; b++) {
			if (sum & (1ll << b) and !(curbm & (1ll << b))) works = false;
		}
		if (works) 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 = 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)
		}
	} else { //a can only be = 1;
		for (int b = maxb-1; b >= 0; b--) {
			curbm = ans ^ (1ll << b);
			memset(dp2,-1,sizeof dp2);
			if (cap2(0) <= B) 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 << ans;
}

# 결과 실행 시간 메모리 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 3 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 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 1 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 5 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 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 6 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 3 ms 492 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 492 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 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 1 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 5 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 3 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 6 ms 492 KB Output is correct
22 Correct 50 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 40 ms 492 KB Output is correct
27 Correct 6 ms 492 KB Output is correct
28 Correct 7 ms 492 KB Output is correct
29 Correct 12 ms 512 KB Output is correct
30 Correct 71 ms 492 KB Output is correct
31 Correct 54 ms 492 KB Output is correct
32 Correct 52 ms 492 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 52 ms 492 KB Output is correct
35 Correct 49 ms 492 KB Output is correct
36 Correct 33 ms 492 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 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 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 6 ms 492 KB Output is correct
15 Correct 7 ms 492 KB Output is correct
16 Correct 11 ms 492 KB Output is correct
17 Correct 32 ms 504 KB Output is correct
18 Correct 62 ms 492 KB Output is correct
19 Correct 50 ms 492 KB Output is correct
20 Correct 5 ms 492 KB Output is correct
21 Correct 54 ms 492 KB Output is correct
22 Correct 50 ms 492 KB Output is correct
23 Correct 33 ms 492 KB Output is correct
24 Correct 57 ms 492 KB Output is correct
25 Correct 61 ms 492 KB Output is correct
26 Correct 168 ms 492 KB Output is correct
27 Correct 408 ms 492 KB Output is correct
28 Correct 553 ms 492 KB Output is correct
29 Correct 521 ms 620 KB Output is correct
30 Correct 16 ms 492 KB Output is correct
31 Correct 466 ms 620 KB Output is correct
32 Correct 549 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 524 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 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 1 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 5 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 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 512 KB Output is correct
25 Correct 4 ms 448 KB Output is correct
26 Correct 5 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 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 3 ms 492 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 4 ms 492 KB Output is correct
37 Correct 8 ms 492 KB Output is correct
38 Correct 7 ms 492 KB Output is correct
39 Correct 12 ms 492 KB Output is correct
40 Correct 32 ms 492 KB Output is correct
41 Correct 54 ms 512 KB Output is correct
42 Correct 50 ms 620 KB Output is correct
43 Correct 6 ms 492 KB Output is correct
44 Correct 53 ms 492 KB Output is correct
45 Correct 50 ms 492 KB Output is correct
46 Correct 33 ms 492 KB Output is correct
47 Correct 57 ms 492 KB Output is correct
48 Correct 62 ms 620 KB Output is correct
49 Correct 172 ms 748 KB Output is correct
50 Correct 389 ms 492 KB Output is correct
51 Correct 548 ms 620 KB Output is correct
52 Correct 512 ms 492 KB Output is correct
53 Correct 17 ms 492 KB Output is correct
54 Correct 471 ms 492 KB Output is correct
55 Correct 547 ms 620 KB Output is correct
56 Correct 39 ms 492 KB Output is correct
57 Correct 146 ms 492 KB Output is correct
58 Correct 282 ms 620 KB Output is correct
59 Correct 394 ms 620 KB Output is correct
60 Correct 164 ms 620 KB Output is correct
61 Correct 6 ms 492 KB Output is correct
62 Correct 379 ms 492 KB Output is correct
63 Correct 420 ms 620 KB Output is correct
64 Correct 338 ms 492 KB Output is correct
65 Correct 42 ms 492 KB Output is correct
66 Correct 53 ms 492 KB Output is correct
67 Correct 130 ms 492 KB Output is correct
68 Correct 301 ms 492 KB Output is correct
69 Correct 392 ms 492 KB Output is correct
70 Correct 161 ms 492 KB Output is correct
71 Correct 11 ms 492 KB Output is correct
72 Correct 380 ms 620 KB Output is correct
73 Correct 392 ms 620 KB Output is correct
74 Correct 387 ms 620 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 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 1 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 5 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 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
21 Correct 3 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 4 ms 492 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 7 ms 492 KB Output is correct
26 Correct 12 ms 492 KB Output is correct
27 Correct 33 ms 492 KB Output is correct
28 Correct 54 ms 492 KB Output is correct
29 Correct 50 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 55 ms 620 KB Output is correct
32 Correct 53 ms 492 KB Output is correct
33 Correct 33 ms 492 KB Output is correct
34 Correct 57 ms 492 KB Output is correct
35 Correct 62 ms 512 KB Output is correct
36 Correct 172 ms 492 KB Output is correct
37 Correct 388 ms 492 KB Output is correct
38 Correct 552 ms 620 KB Output is correct
39 Correct 509 ms 492 KB Output is correct
40 Correct 17 ms 492 KB Output is correct
41 Correct 472 ms 492 KB Output is correct
42 Correct 545 ms 620 KB Output is correct
43 Correct 39 ms 492 KB Output is correct
44 Correct 149 ms 492 KB Output is correct
45 Correct 284 ms 620 KB Output is correct
46 Correct 399 ms 620 KB Output is correct
47 Correct 162 ms 620 KB Output is correct
48 Correct 6 ms 492 KB Output is correct
49 Correct 378 ms 492 KB Output is correct
50 Correct 420 ms 620 KB Output is correct
51 Correct 20 ms 364 KB Output is correct
52 Correct 804 ms 492 KB Output is correct
53 Correct 748 ms 364 KB Output is correct
54 Execution timed out 1096 ms 492 KB Time limit exceeded
55 Halted 0 ms 0 KB -