Submission #402874

# Submission time Handle Problem Language Result Execution time Memory
402874 2021-05-12T13:06:28 Z yoavL Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 332 KB
#include <iostream>
#include <vector>
#include <algorithm>

#define upmax(a, b) a = max(a, b);
#define upmin(a, b) a = min(a, b);
#define pr(x) cout << x << endl;
#define wpr(x) cout << #x << ": " << x << endl;

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;

const ll bits = 62;
ll n, a, b;
vll arr;


inline bool check(ll bit, ll mask, ll x)
{
	mask >>= bit;
	x >>= bit;
	if ((mask | x) == mask) {
		return true;
	}
	return false;
}

bool check2(ll mask, ll bit)
{
	// dp[i][j] = is it possible to make it ok for mask with i first vals using j groups?	
	vvb dp(n + 1, vb(b+1, 0));
	dp[0][0] = 1;
	for (ll i = 0; i <= n; i++) {
		for (ll j = 0; j < b; j++) {
			if (!dp[i][j]) continue;
			ll csum = 0;
			for (ll k = i + 1; k <= n; k++) {
				csum += arr[k - 1];
				if (check(bit, mask, csum)) {
					dp[k][j + 1] = 1;
				}
			}
		}
	}
	/*
	if (bit <= 4) {
		wpr(bit);
		wpr(mask);
		pr("dp:");
		for (ll i = 0; i <= n; i++) {
			for (ll j = 0; j <= b; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}
	}
	*/
	
	for (ll j = a; j <= b; j++) {
		//pr(j);
		if (dp[n][j]) return true;
	}
	return false;
}


int main()
{
	cin >> n >> a >> b;
	arr.resize(n);
	for (ll i = 0; i < n; i++) cin >> arr[i];
	//ll mask = ((ll)1 << bits) - (ll)1;
	ll mask = 0;
	for (ll bit = bits - 1; bit >= 0; bit--) {
		//wpr(mask);
		//mask -= (ll)1 << bit;
		if (!check2(mask, bit)) mask += (ll)1 << bit;
		/*
		if (a == 1) {
			if (!check2(mask, bit)) mask += (ll)1 << bit;
		}
		else {
			if (!check2(mask, bit)) mask += (ll)1 << bit;
		}
		*/
		//wpr(mask);
	}
	pr(mask);
}

/*

6 1 3 
8 1 2 1 5 4

8 1 4 
1 2 1 1 1 0 4 6 


3 2 3
1 3 4

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 3 ms 204 KB Output is correct
31 Correct 4 ms 204 KB Output is correct
32 Correct 5 ms 292 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 4 ms 204 KB Output is correct
35 Correct 4 ms 292 KB Output is correct
36 Correct 3 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 3 ms 204 KB Output is correct
18 Correct 5 ms 204 KB Output is correct
19 Correct 4 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 5 ms 204 KB Output is correct
22 Correct 4 ms 204 KB Output is correct
23 Correct 3 ms 204 KB Output is correct
24 Correct 4 ms 204 KB Output is correct
25 Correct 4 ms 280 KB Output is correct
26 Correct 10 ms 292 KB Output is correct
27 Correct 23 ms 296 KB Output is correct
28 Correct 31 ms 204 KB Output is correct
29 Correct 31 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 27 ms 204 KB Output is correct
32 Correct 30 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 2 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 2 ms 204 KB Output is correct
40 Correct 3 ms 288 KB Output is correct
41 Correct 4 ms 204 KB Output is correct
42 Correct 4 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 4 ms 204 KB Output is correct
45 Correct 4 ms 204 KB Output is correct
46 Correct 3 ms 204 KB Output is correct
47 Correct 4 ms 204 KB Output is correct
48 Correct 4 ms 204 KB Output is correct
49 Correct 10 ms 204 KB Output is correct
50 Correct 23 ms 276 KB Output is correct
51 Correct 32 ms 296 KB Output is correct
52 Correct 33 ms 204 KB Output is correct
53 Correct 2 ms 204 KB Output is correct
54 Correct 27 ms 296 KB Output is correct
55 Correct 30 ms 204 KB Output is correct
56 Correct 3 ms 204 KB Output is correct
57 Correct 7 ms 296 KB Output is correct
58 Correct 14 ms 204 KB Output is correct
59 Correct 18 ms 300 KB Output is correct
60 Correct 18 ms 280 KB Output is correct
61 Correct 1 ms 300 KB Output is correct
62 Correct 19 ms 204 KB Output is correct
63 Correct 20 ms 300 KB Output is correct
64 Correct 25 ms 204 KB Output is correct
65 Correct 3 ms 204 KB Output is correct
66 Correct 3 ms 204 KB Output is correct
67 Correct 6 ms 224 KB Output is correct
68 Correct 14 ms 300 KB Output is correct
69 Correct 18 ms 204 KB Output is correct
70 Correct 18 ms 204 KB Output is correct
71 Correct 2 ms 204 KB Output is correct
72 Correct 20 ms 292 KB Output is correct
73 Correct 19 ms 300 KB Output is correct
74 Correct 18 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 248 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 3 ms 292 KB Output is correct
28 Correct 5 ms 204 KB Output is correct
29 Correct 4 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 4 ms 204 KB Output is correct
32 Correct 4 ms 204 KB Output is correct
33 Correct 3 ms 204 KB Output is correct
34 Correct 5 ms 204 KB Output is correct
35 Correct 4 ms 204 KB Output is correct
36 Correct 10 ms 204 KB Output is correct
37 Correct 24 ms 204 KB Output is correct
38 Correct 32 ms 272 KB Output is correct
39 Correct 33 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 28 ms 292 KB Output is correct
42 Correct 30 ms 300 KB Output is correct
43 Correct 3 ms 204 KB Output is correct
44 Correct 7 ms 316 KB Output is correct
45 Correct 14 ms 204 KB Output is correct
46 Correct 20 ms 204 KB Output is correct
47 Correct 19 ms 300 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 19 ms 204 KB Output is correct
50 Correct 20 ms 204 KB Output is correct
51 Correct 10 ms 304 KB Output is correct
52 Execution timed out 1088 ms 332 KB Time limit exceeded
53 Halted 0 ms 0 KB -