답안 #332985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332985 2020-12-04T07:30:44 Z Cantfindme Bali Sculptures (APIO15_sculpture) C++17
71 / 100
640 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 = 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 & (1ll << b) and !(curbm & (1ll << 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;
}

# 결과 실행 시간 메모리 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 512 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 3 ms 508 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 8 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 512 KB Output is correct
29 Correct 2 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 4 ms 492 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 3 ms 492 KB Output is correct
36 Correct 5 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 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 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 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 5 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 6 ms 492 KB Output is correct
28 Correct 8 ms 492 KB Output is correct
29 Correct 13 ms 492 KB Output is correct
30 Correct 37 ms 492 KB Output is correct
31 Correct 62 ms 492 KB Output is correct
32 Correct 58 ms 492 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 60 ms 492 KB Output is correct
35 Correct 58 ms 492 KB Output is correct
36 Correct 38 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 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 4 ms 512 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 6 ms 492 KB Output is correct
14 Correct 6 ms 492 KB Output is correct
15 Correct 8 ms 492 KB Output is correct
16 Correct 13 ms 384 KB Output is correct
17 Correct 38 ms 492 KB Output is correct
18 Correct 62 ms 492 KB Output is correct
19 Correct 58 ms 492 KB Output is correct
20 Correct 8 ms 492 KB Output is correct
21 Correct 60 ms 492 KB Output is correct
22 Correct 56 ms 492 KB Output is correct
23 Correct 41 ms 492 KB Output is correct
24 Correct 64 ms 492 KB Output is correct
25 Correct 70 ms 492 KB Output is correct
26 Correct 196 ms 492 KB Output is correct
27 Correct 457 ms 492 KB Output is correct
28 Correct 630 ms 620 KB Output is correct
29 Correct 590 ms 492 KB Output is correct
30 Correct 22 ms 492 KB Output is correct
31 Correct 548 ms 492 KB Output is correct
32 Correct 628 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 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 3 ms 492 KB Output is correct
13 Correct 6 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 512 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 6 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 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 4 ms 492 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 5 ms 492 KB Output is correct
37 Correct 7 ms 492 KB Output is correct
38 Correct 8 ms 492 KB Output is correct
39 Correct 13 ms 492 KB Output is correct
40 Correct 37 ms 492 KB Output is correct
41 Correct 63 ms 492 KB Output is correct
42 Correct 58 ms 640 KB Output is correct
43 Correct 6 ms 492 KB Output is correct
44 Correct 60 ms 492 KB Output is correct
45 Correct 58 ms 492 KB Output is correct
46 Correct 39 ms 492 KB Output is correct
47 Correct 64 ms 620 KB Output is correct
48 Correct 73 ms 492 KB Output is correct
49 Correct 200 ms 492 KB Output is correct
50 Correct 449 ms 492 KB Output is correct
51 Correct 633 ms 620 KB Output is correct
52 Correct 600 ms 620 KB Output is correct
53 Correct 20 ms 492 KB Output is correct
54 Correct 543 ms 492 KB Output is correct
55 Correct 632 ms 492 KB Output is correct
56 Correct 60 ms 492 KB Output is correct
57 Correct 211 ms 492 KB Output is correct
58 Correct 427 ms 492 KB Output is correct
59 Correct 610 ms 620 KB Output is correct
60 Correct 242 ms 492 KB Output is correct
61 Correct 8 ms 492 KB Output is correct
62 Correct 538 ms 620 KB Output is correct
63 Correct 578 ms 620 KB Output is correct
64 Correct 377 ms 492 KB Output is correct
65 Correct 61 ms 492 KB Output is correct
66 Correct 77 ms 492 KB Output is correct
67 Correct 192 ms 492 KB Output is correct
68 Correct 451 ms 492 KB Output is correct
69 Correct 601 ms 492 KB Output is correct
70 Correct 244 ms 496 KB Output is correct
71 Correct 16 ms 492 KB Output is correct
72 Correct 540 ms 492 KB Output is correct
73 Correct 544 ms 492 KB Output is correct
74 Correct 538 ms 492 KB Output is correct
# 결과 실행 시간 메모리 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 4 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 3 ms 492 KB Output is correct
13 Correct 6 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 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 4 ms 492 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 5 ms 492 KB Output is correct
24 Correct 6 ms 492 KB Output is correct
25 Correct 8 ms 492 KB Output is correct
26 Correct 13 ms 492 KB Output is correct
27 Correct 36 ms 492 KB Output is correct
28 Correct 62 ms 492 KB Output is correct
29 Correct 58 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 61 ms 492 KB Output is correct
32 Correct 56 ms 492 KB Output is correct
33 Correct 38 ms 492 KB Output is correct
34 Correct 66 ms 492 KB Output is correct
35 Correct 71 ms 492 KB Output is correct
36 Correct 202 ms 492 KB Output is correct
37 Correct 449 ms 492 KB Output is correct
38 Correct 640 ms 620 KB Output is correct
39 Correct 599 ms 492 KB Output is correct
40 Correct 20 ms 492 KB Output is correct
41 Correct 543 ms 492 KB Output is correct
42 Correct 632 ms 492 KB Output is correct
43 Correct 58 ms 492 KB Output is correct
44 Correct 211 ms 492 KB Output is correct
45 Correct 426 ms 492 KB Output is correct
46 Correct 610 ms 492 KB Output is correct
47 Correct 244 ms 492 KB Output is correct
48 Correct 10 ms 492 KB Output is correct
49 Correct 543 ms 492 KB Output is correct
50 Correct 578 ms 620 KB Output is correct
51 Incorrect 1 ms 364 KB Output isn't correct
52 Halted 0 ms 0 KB -