Submission #39458

# Submission time Handle Problem Language Result Execution time Memory
39458 2018-01-15T15:11:59 Z qoo2p5 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
149 ms 2224 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;

#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define sz(x) ((int) (x).size())
#define mp make_pair
#define pb push_back

bool mini(auto &x, const auto &y) {
	if (y < x) {
		x = y;
		return 1;
	}
	return 0;
}

bool maxi(auto &x, const auto &y) {
	if (y < x) {
		x = y;
		return 1;
	}
	return 0;
}

void run();

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	run();
	return 0;
}

const int N = 2005;
const int L = 42;

int n, a, b;
ll x[N], p[N];

ll get(int l, int r) {
	return p[r] - (l == 0 ? 0 : p[l - 1]);
}

namespace SmallN {
	const int SN = 105;
	bool dp[SN][SN];
	
	void solve() {
		ll ans = 0;
		ll deny = 0;
		
		per(bit, L, 0) {
			memset(dp, 0, sizeof dp);
			dp[0][0] = 1;
			deny |= (1LL << bit);
			rep(i, 0, n) {
				rep(cnt, 0, b) {
					if (!dp[i][cnt]) continue;
					
					rep(j, i, n) {
						ll s = get(i, j);
						if (s & deny) continue;
						
						dp[j + 1][cnt + 1] = 1;
					}
				}
			}
			
			bool ok = 0;
			rep(i, a, b + 1) ok |= dp[n][i];
			if (!ok) {
				deny ^= (1LL << bit);
				ans |= (1LL << bit);
			}
		}
		
		cout << ans << "\n";
	}
};

namespace LastGroup {
	int dp[N];
	
	void solve() {
		ll ans = 0;
		ll deny = 0;
		
		per(bit, L, 0) {
			fill(dp, dp + N, INF);
			dp[0] = 0;
			deny |= (1LL << bit);
			rep(i, 0, n) {
				rep(j, i, n) {
					ll s = get(i, j);
					if (s & deny) continue;
					mini(dp[j + 1], dp[i] + 1);
				}
			}
			
			bool ok = dp[n] <= b;
			if (!ok) {
				deny ^= (1LL << bit);
				ans |= (1LL << bit);
			}
		}
		
		cout << ans << "\n";
	}
};

void run() {
	cin >> n >> a >> b;
	rep(i, 0, n) {
		cin >> x[i];
	}
	partial_sum(x, x + n, p);
	
	if (n <= 100) {
		SmallN::solve();
	} else {
		LastGroup::solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2224 KB Output is correct
2 Correct 0 ms 2224 KB Output is correct
3 Correct 0 ms 2224 KB Output is correct
4 Correct 0 ms 2224 KB Output is correct
5 Correct 0 ms 2224 KB Output is correct
6 Correct 0 ms 2224 KB Output is correct
7 Correct 0 ms 2224 KB Output is correct
8 Correct 0 ms 2224 KB Output is correct
9 Correct 0 ms 2224 KB Output is correct
10 Correct 0 ms 2224 KB Output is correct
11 Correct 0 ms 2224 KB Output is correct
12 Correct 0 ms 2224 KB Output is correct
13 Correct 0 ms 2224 KB Output is correct
14 Correct 0 ms 2224 KB Output is correct
15 Correct 0 ms 2224 KB Output is correct
16 Correct 0 ms 2224 KB Output is correct
17 Correct 0 ms 2224 KB Output is correct
18 Correct 0 ms 2224 KB Output is correct
19 Correct 0 ms 2224 KB Output is correct
20 Correct 0 ms 2224 KB Output is correct
21 Correct 0 ms 2224 KB Output is correct
22 Correct 0 ms 2224 KB Output is correct
23 Correct 0 ms 2224 KB Output is correct
24 Correct 0 ms 2224 KB Output is correct
25 Correct 0 ms 2224 KB Output is correct
26 Correct 0 ms 2224 KB Output is correct
27 Correct 0 ms 2224 KB Output is correct
28 Correct 0 ms 2224 KB Output is correct
29 Correct 0 ms 2224 KB Output is correct
30 Correct 0 ms 2224 KB Output is correct
31 Correct 0 ms 2224 KB Output is correct
32 Correct 0 ms 2224 KB Output is correct
33 Correct 0 ms 2224 KB Output is correct
34 Correct 0 ms 2224 KB Output is correct
35 Correct 0 ms 2224 KB Output is correct
36 Correct 0 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2224 KB Output is correct
2 Correct 0 ms 2224 KB Output is correct
3 Correct 0 ms 2224 KB Output is correct
4 Correct 0 ms 2224 KB Output is correct
5 Correct 0 ms 2224 KB Output is correct
6 Correct 0 ms 2224 KB Output is correct
7 Correct 0 ms 2224 KB Output is correct
8 Correct 0 ms 2224 KB Output is correct
9 Correct 0 ms 2224 KB Output is correct
10 Correct 0 ms 2224 KB Output is correct
11 Correct 0 ms 2224 KB Output is correct
12 Correct 0 ms 2224 KB Output is correct
13 Correct 0 ms 2224 KB Output is correct
14 Correct 0 ms 2224 KB Output is correct
15 Correct 0 ms 2224 KB Output is correct
16 Correct 0 ms 2224 KB Output is correct
17 Correct 0 ms 2224 KB Output is correct
18 Correct 0 ms 2224 KB Output is correct
19 Correct 0 ms 2224 KB Output is correct
20 Correct 0 ms 2224 KB Output is correct
21 Correct 0 ms 2224 KB Output is correct
22 Correct 0 ms 2224 KB Output is correct
23 Correct 0 ms 2224 KB Output is correct
24 Correct 0 ms 2224 KB Output is correct
25 Correct 0 ms 2224 KB Output is correct
26 Correct 0 ms 2224 KB Output is correct
27 Correct 0 ms 2224 KB Output is correct
28 Correct 0 ms 2224 KB Output is correct
29 Correct 0 ms 2224 KB Output is correct
30 Correct 0 ms 2224 KB Output is correct
31 Correct 0 ms 2224 KB Output is correct
32 Correct 0 ms 2224 KB Output is correct
33 Correct 0 ms 2224 KB Output is correct
34 Correct 0 ms 2224 KB Output is correct
35 Correct 0 ms 2224 KB Output is correct
36 Correct 0 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2224 KB Output is correct
2 Correct 0 ms 2224 KB Output is correct
3 Correct 0 ms 2224 KB Output is correct
4 Correct 0 ms 2224 KB Output is correct
5 Correct 0 ms 2224 KB Output is correct
6 Correct 0 ms 2224 KB Output is correct
7 Correct 0 ms 2224 KB Output is correct
8 Correct 0 ms 2224 KB Output is correct
9 Correct 0 ms 2224 KB Output is correct
10 Correct 0 ms 2224 KB Output is correct
11 Correct 0 ms 2224 KB Output is correct
12 Correct 0 ms 2224 KB Output is correct
13 Correct 0 ms 2224 KB Output is correct
14 Correct 0 ms 2224 KB Output is correct
15 Correct 0 ms 2224 KB Output is correct
16 Correct 0 ms 2224 KB Output is correct
17 Correct 0 ms 2224 KB Output is correct
18 Correct 0 ms 2224 KB Output is correct
19 Correct 0 ms 2224 KB Output is correct
20 Correct 0 ms 2224 KB Output is correct
21 Correct 0 ms 2224 KB Output is correct
22 Correct 0 ms 2224 KB Output is correct
23 Correct 0 ms 2224 KB Output is correct
24 Correct 0 ms 2224 KB Output is correct
25 Correct 3 ms 2224 KB Output is correct
26 Correct 3 ms 2224 KB Output is correct
27 Correct 9 ms 2224 KB Output is correct
28 Correct 19 ms 2224 KB Output is correct
29 Correct 16 ms 2224 KB Output is correct
30 Correct 0 ms 2224 KB Output is correct
31 Correct 13 ms 2224 KB Output is correct
32 Correct 13 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2224 KB Output is correct
2 Correct 0 ms 2224 KB Output is correct
3 Correct 0 ms 2224 KB Output is correct
4 Correct 0 ms 2224 KB Output is correct
5 Correct 0 ms 2224 KB Output is correct
6 Correct 0 ms 2224 KB Output is correct
7 Correct 0 ms 2224 KB Output is correct
8 Correct 0 ms 2224 KB Output is correct
9 Correct 0 ms 2224 KB Output is correct
10 Correct 0 ms 2224 KB Output is correct
11 Correct 0 ms 2224 KB Output is correct
12 Correct 0 ms 2224 KB Output is correct
13 Correct 0 ms 2224 KB Output is correct
14 Correct 0 ms 2224 KB Output is correct
15 Correct 0 ms 2224 KB Output is correct
16 Correct 0 ms 2224 KB Output is correct
17 Correct 0 ms 2224 KB Output is correct
18 Correct 0 ms 2224 KB Output is correct
19 Correct 0 ms 2224 KB Output is correct
20 Correct 0 ms 2224 KB Output is correct
21 Correct 0 ms 2224 KB Output is correct
22 Correct 0 ms 2224 KB Output is correct
23 Correct 0 ms 2224 KB Output is correct
24 Correct 0 ms 2224 KB Output is correct
25 Correct 0 ms 2224 KB Output is correct
26 Correct 0 ms 2224 KB Output is correct
27 Correct 0 ms 2224 KB Output is correct
28 Correct 0 ms 2224 KB Output is correct
29 Correct 0 ms 2224 KB Output is correct
30 Correct 0 ms 2224 KB Output is correct
31 Correct 0 ms 2224 KB Output is correct
32 Correct 0 ms 2224 KB Output is correct
33 Correct 0 ms 2224 KB Output is correct
34 Correct 0 ms 2224 KB Output is correct
35 Correct 0 ms 2224 KB Output is correct
36 Correct 0 ms 2224 KB Output is correct
37 Correct 0 ms 2224 KB Output is correct
38 Correct 0 ms 2224 KB Output is correct
39 Correct 0 ms 2224 KB Output is correct
40 Correct 0 ms 2224 KB Output is correct
41 Correct 0 ms 2224 KB Output is correct
42 Correct 3 ms 2224 KB Output is correct
43 Correct 0 ms 2224 KB Output is correct
44 Correct 3 ms 2224 KB Output is correct
45 Correct 0 ms 2224 KB Output is correct
46 Correct 0 ms 2224 KB Output is correct
47 Correct 0 ms 2224 KB Output is correct
48 Correct 3 ms 2224 KB Output is correct
49 Correct 3 ms 2224 KB Output is correct
50 Correct 9 ms 2224 KB Output is correct
51 Correct 16 ms 2224 KB Output is correct
52 Correct 16 ms 2224 KB Output is correct
53 Correct 0 ms 2224 KB Output is correct
54 Correct 13 ms 2224 KB Output is correct
55 Correct 16 ms 2224 KB Output is correct
56 Correct 0 ms 2224 KB Output is correct
57 Correct 0 ms 2224 KB Output is correct
58 Correct 3 ms 2224 KB Output is correct
59 Correct 6 ms 2224 KB Output is correct
60 Correct 6 ms 2224 KB Output is correct
61 Correct 0 ms 2224 KB Output is correct
62 Correct 6 ms 2224 KB Output is correct
63 Correct 6 ms 2224 KB Output is correct
64 Correct 13 ms 2224 KB Output is correct
65 Correct 0 ms 2224 KB Output is correct
66 Correct 0 ms 2224 KB Output is correct
67 Correct 0 ms 2224 KB Output is correct
68 Correct 3 ms 2224 KB Output is correct
69 Correct 6 ms 2224 KB Output is correct
70 Correct 6 ms 2224 KB Output is correct
71 Correct 0 ms 2224 KB Output is correct
72 Correct 6 ms 2224 KB Output is correct
73 Correct 9 ms 2224 KB Output is correct
74 Correct 6 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2224 KB Output is correct
2 Correct 0 ms 2224 KB Output is correct
3 Correct 0 ms 2224 KB Output is correct
4 Correct 0 ms 2224 KB Output is correct
5 Correct 0 ms 2224 KB Output is correct
6 Correct 0 ms 2224 KB Output is correct
7 Correct 0 ms 2224 KB Output is correct
8 Correct 0 ms 2224 KB Output is correct
9 Correct 0 ms 2224 KB Output is correct
10 Correct 0 ms 2224 KB Output is correct
11 Correct 0 ms 2224 KB Output is correct
12 Correct 0 ms 2224 KB Output is correct
13 Correct 0 ms 2224 KB Output is correct
14 Correct 0 ms 2224 KB Output is correct
15 Correct 0 ms 2224 KB Output is correct
16 Correct 0 ms 2224 KB Output is correct
17 Correct 0 ms 2224 KB Output is correct
18 Correct 0 ms 2224 KB Output is correct
19 Correct 0 ms 2224 KB Output is correct
20 Correct 0 ms 2224 KB Output is correct
21 Correct 0 ms 2224 KB Output is correct
22 Correct 0 ms 2224 KB Output is correct
23 Correct 0 ms 2224 KB Output is correct
24 Correct 0 ms 2224 KB Output is correct
25 Correct 0 ms 2224 KB Output is correct
26 Correct 0 ms 2224 KB Output is correct
27 Correct 0 ms 2224 KB Output is correct
28 Correct 0 ms 2224 KB Output is correct
29 Correct 0 ms 2224 KB Output is correct
30 Correct 0 ms 2224 KB Output is correct
31 Correct 0 ms 2224 KB Output is correct
32 Correct 0 ms 2224 KB Output is correct
33 Correct 0 ms 2224 KB Output is correct
34 Correct 0 ms 2224 KB Output is correct
35 Correct 0 ms 2224 KB Output is correct
36 Correct 3 ms 2224 KB Output is correct
37 Correct 9 ms 2224 KB Output is correct
38 Correct 13 ms 2224 KB Output is correct
39 Correct 16 ms 2224 KB Output is correct
40 Correct 0 ms 2224 KB Output is correct
41 Correct 13 ms 2224 KB Output is correct
42 Correct 13 ms 2224 KB Output is correct
43 Correct 0 ms 2224 KB Output is correct
44 Correct 0 ms 2224 KB Output is correct
45 Correct 3 ms 2224 KB Output is correct
46 Correct 3 ms 2224 KB Output is correct
47 Correct 3 ms 2224 KB Output is correct
48 Correct 0 ms 2224 KB Output is correct
49 Correct 6 ms 2224 KB Output is correct
50 Correct 6 ms 2224 KB Output is correct
51 Correct 0 ms 2224 KB Output is correct
52 Correct 13 ms 2224 KB Output is correct
53 Correct 19 ms 2224 KB Output is correct
54 Correct 36 ms 2224 KB Output is correct
55 Correct 33 ms 2224 KB Output is correct
56 Correct 129 ms 2224 KB Output is correct
57 Correct 129 ms 2224 KB Output is correct
58 Correct 126 ms 2224 KB Output is correct
59 Correct 126 ms 2224 KB Output is correct
60 Correct 149 ms 2224 KB Output is correct
61 Correct 0 ms 2224 KB Output is correct
62 Correct 23 ms 2224 KB Output is correct
63 Correct 36 ms 2224 KB Output is correct
64 Correct 29 ms 2224 KB Output is correct
65 Correct 69 ms 2224 KB Output is correct
66 Correct 96 ms 2224 KB Output is correct
67 Correct 126 ms 2224 KB Output is correct
68 Correct 136 ms 2224 KB Output is correct
69 Correct 146 ms 2224 KB Output is correct