답안 #332986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332986 2020-12-04T07:35:57 Z Cantfindme Bali Sculptures (APIO15_sculpture) C++17
71 / 100
1000 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;
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() {
	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 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 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 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 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 2 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 4 ms 364 KB Output is correct
34 Correct 4 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 5 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 4 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 6 ms 512 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 2 ms 364 KB Output is correct
19 Correct 3 ms 512 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 8 ms 364 KB Output is correct
27 Correct 7 ms 364 KB Output is correct
28 Correct 9 ms 364 KB Output is correct
29 Correct 15 ms 492 KB Output is correct
30 Correct 42 ms 364 KB Output is correct
31 Correct 71 ms 492 KB Output is correct
32 Correct 65 ms 492 KB Output is correct
33 Correct 6 ms 492 KB Output is correct
34 Correct 70 ms 492 KB Output is correct
35 Correct 65 ms 488 KB Output is correct
36 Correct 44 ms 492 KB Output is correct
# 결과 실행 시간 메모리 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 6 ms 364 KB Output is correct
14 Correct 7 ms 364 KB Output is correct
15 Correct 10 ms 364 KB Output is correct
16 Correct 15 ms 364 KB Output is correct
17 Correct 43 ms 364 KB Output is correct
18 Correct 70 ms 492 KB Output is correct
19 Correct 64 ms 492 KB Output is correct
20 Correct 6 ms 492 KB Output is correct
21 Correct 71 ms 492 KB Output is correct
22 Correct 67 ms 492 KB Output is correct
23 Correct 44 ms 492 KB Output is correct
24 Correct 74 ms 492 KB Output is correct
25 Correct 80 ms 492 KB Output is correct
26 Correct 225 ms 492 KB Output is correct
27 Correct 523 ms 492 KB Output is correct
28 Correct 730 ms 492 KB Output is correct
29 Correct 649 ms 620 KB Output is correct
30 Correct 21 ms 620 KB Output is correct
31 Correct 626 ms 488 KB Output is correct
32 Correct 721 ms 488 KB Output is correct
# 결과 실행 시간 메모리 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 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 2 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 4 ms 364 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 3 ms 364 KB Output is correct
36 Correct 5 ms 364 KB Output is correct
37 Correct 7 ms 364 KB Output is correct
38 Correct 10 ms 364 KB Output is correct
39 Correct 15 ms 364 KB Output is correct
40 Correct 43 ms 364 KB Output is correct
41 Correct 70 ms 492 KB Output is correct
42 Correct 65 ms 492 KB Output is correct
43 Correct 6 ms 492 KB Output is correct
44 Correct 73 ms 492 KB Output is correct
45 Correct 65 ms 492 KB Output is correct
46 Correct 44 ms 492 KB Output is correct
47 Correct 75 ms 492 KB Output is correct
48 Correct 80 ms 492 KB Output is correct
49 Correct 227 ms 492 KB Output is correct
50 Correct 520 ms 492 KB Output is correct
51 Correct 740 ms 492 KB Output is correct
52 Correct 655 ms 492 KB Output is correct
53 Correct 21 ms 492 KB Output is correct
54 Correct 634 ms 492 KB Output is correct
55 Correct 728 ms 492 KB Output is correct
56 Correct 64 ms 492 KB Output is correct
57 Correct 231 ms 492 KB Output is correct
58 Correct 474 ms 492 KB Output is correct
59 Correct 669 ms 492 KB Output is correct
60 Correct 233 ms 492 KB Output is correct
61 Correct 8 ms 492 KB Output is correct
62 Correct 608 ms 492 KB Output is correct
63 Correct 658 ms 492 KB Output is correct
64 Correct 455 ms 492 KB Output is correct
65 Correct 67 ms 492 KB Output is correct
66 Correct 83 ms 488 KB Output is correct
67 Correct 212 ms 492 KB Output is correct
68 Correct 494 ms 492 KB Output is correct
69 Correct 663 ms 492 KB Output is correct
70 Correct 235 ms 492 KB Output is correct
71 Correct 15 ms 492 KB Output is correct
72 Correct 613 ms 492 KB Output is correct
73 Correct 623 ms 492 KB Output is correct
74 Correct 597 ms 492 KB Output is correct
# 결과 실행 시간 메모리 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 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 492 KB Output is correct
11 Correct 2 ms 492 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 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 4 ms 364 KB Output is correct
21 Correct 4 ms 364 KB Output is correct
22 Correct 3 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 7 ms 364 KB Output is correct
25 Correct 9 ms 364 KB Output is correct
26 Correct 14 ms 364 KB Output is correct
27 Correct 42 ms 364 KB Output is correct
28 Correct 70 ms 492 KB Output is correct
29 Correct 64 ms 492 KB Output is correct
30 Correct 6 ms 492 KB Output is correct
31 Correct 70 ms 492 KB Output is correct
32 Correct 65 ms 492 KB Output is correct
33 Correct 44 ms 492 KB Output is correct
34 Correct 75 ms 492 KB Output is correct
35 Correct 83 ms 492 KB Output is correct
36 Correct 227 ms 492 KB Output is correct
37 Correct 522 ms 492 KB Output is correct
38 Correct 728 ms 492 KB Output is correct
39 Correct 650 ms 492 KB Output is correct
40 Correct 21 ms 492 KB Output is correct
41 Correct 627 ms 492 KB Output is correct
42 Correct 727 ms 492 KB Output is correct
43 Correct 64 ms 492 KB Output is correct
44 Correct 231 ms 492 KB Output is correct
45 Correct 477 ms 492 KB Output is correct
46 Correct 664 ms 492 KB Output is correct
47 Correct 228 ms 492 KB Output is correct
48 Correct 8 ms 492 KB Output is correct
49 Correct 611 ms 492 KB Output is correct
50 Correct 648 ms 492 KB Output is correct
51 Correct 27 ms 364 KB Output is correct
52 Execution timed out 1028 ms 448 KB Time limit exceeded
53 Halted 0 ms 0 KB -