Submission #475720

# Submission time Handle Problem Language Result Execution time Memory
475720 2021-09-23T20:18:33 Z thiago_bastos Bali Sculptures (APIO15_sculpture) C++17
71 / 100
1000 ms 22912 KB
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned;
using i16 = short;
using u16 = unsigned short;
using ld = long double;
using ii = pair<int, int>;

const int N = 2e3, inf = 1e9;

i64 c[N][N];
bitset<101> dp[101];
vector<int> DP;
int n, l, r;

bool sub1(i64 mask, i64 X) {
	
	fill(DP.begin(), DP.end(), inf);
				
	i64 S = mask | X;
				
	for(int i = 0; i < n; ++i) {
		for(int j = i - 1; j >= 0; --j) {
			if((c[j + 1][i] & ~S) <= X)
				DP[i] = min(DP[i], DP[j] + 1);
		}
		if((c[0][i] & ~S) <= X) DP[i] = 1;
	}
	
	if(DP.back() <= r) return true;

	return false;
}

bool sub2(i64 mask, i64 X) {

	for(int i = 0; i < n; ++i) dp[i].reset();
				
	i64 S = mask | X;
				
	for(int i = 0; i < n; ++i) {
		if((c[0][i] & ~S) <= X) dp[i][1] = 1;
		for(int j = i - 1; j >= 0; --j) {
			if((c[j + 1][i] & ~S) <= X) dp[i] = dp[i] | (dp[j] << 1);
		}
	}
				
	for(int i = l; i <= r; ++i) if(dp[n - 1][i]) return true;
			
	return false;
}

void solve() {
	
	cin >> n >> l >> r;
	
	vector<int> a(n);
	DP.resize(n);
	
	for(int i = 0; i < n; ++i) cin >> a[i];
	
	for(int i = 0; i < n; ++i) {
		i64 x = 0;
		for(int j = i; j < n; ++j) c[i][j] = x += a[j];
	}
	
	if(l == 1) {
		i64 mask = 0;
		
		for(int m = 45; m > 0; ) {
			if(sub1(mask, 0)) break;
			for(int k = 0; k < m; ++k) {
				if(sub1(mask, 1LL << k)) {
					mask |= 1LL << k;
					m = k;
					break;
				}
			}
		}
		
		cout << mask << '\n';
	} else {
		i64 mask = 0;
		
		for(int m = 45; m > 0; ) {
			if(sub2(mask, 0)) break;
			for(int k = 0; k < m; ++k) {
				if(sub2(mask, 1LL << k)) {
					mask |= 1LL << k;
					m = k;
					break;
				}
			}
		}
		
		cout << mask << '\n';
	}
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
 	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 0 ms 460 KB Output is correct
22 Correct 1 ms 452 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 592 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 720 KB Output is correct
29 Correct 1 ms 720 KB Output is correct
30 Correct 1 ms 716 KB Output is correct
31 Correct 1 ms 716 KB Output is correct
32 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 0 ms 336 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 0 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 588 KB Output is correct
49 Correct 1 ms 588 KB Output is correct
50 Correct 1 ms 588 KB Output is correct
51 Correct 1 ms 716 KB Output is correct
52 Correct 1 ms 716 KB Output is correct
53 Correct 1 ms 716 KB Output is correct
54 Correct 1 ms 716 KB Output is correct
55 Correct 1 ms 716 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 3 ms 588 KB Output is correct
58 Correct 3 ms 588 KB Output is correct
59 Correct 5 ms 752 KB Output is correct
60 Correct 3 ms 704 KB Output is correct
61 Correct 3 ms 716 KB Output is correct
62 Correct 4 ms 716 KB Output is correct
63 Correct 4 ms 716 KB Output is correct
64 Correct 1 ms 588 KB Output is correct
65 Correct 1 ms 460 KB Output is correct
66 Correct 2 ms 460 KB Output is correct
67 Correct 2 ms 576 KB Output is correct
68 Correct 3 ms 588 KB Output is correct
69 Correct 3 ms 716 KB Output is correct
70 Correct 2 ms 716 KB Output is correct
71 Correct 2 ms 716 KB Output is correct
72 Correct 3 ms 716 KB Output is correct
73 Correct 3 ms 716 KB Output is correct
74 Correct 3 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
27 Correct 1 ms 444 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 452 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 0 ms 460 KB Output is correct
33 Correct 0 ms 460 KB Output is correct
34 Correct 0 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 648 KB Output is correct
39 Correct 1 ms 716 KB Output is correct
40 Correct 1 ms 716 KB Output is correct
41 Correct 1 ms 716 KB Output is correct
42 Correct 1 ms 716 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 3 ms 588 KB Output is correct
45 Correct 3 ms 588 KB Output is correct
46 Correct 4 ms 696 KB Output is correct
47 Correct 3 ms 720 KB Output is correct
48 Correct 3 ms 748 KB Output is correct
49 Correct 6 ms 716 KB Output is correct
50 Correct 4 ms 700 KB Output is correct
51 Correct 4 ms 768 KB Output is correct
52 Correct 94 ms 3916 KB Output is correct
53 Correct 240 ms 5452 KB Output is correct
54 Correct 390 ms 8280 KB Output is correct
55 Correct 350 ms 8288 KB Output is correct
56 Execution timed out 1096 ms 22912 KB Time limit exceeded
57 Halted 0 ms 0 KB -