#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 2e3 + 10;
const ll LOG = 50;
ll A[MAXN], n, a, b;
bool dp[MAXN][MAXN];
int dp2[MAXN];
inline bool check2(ll mask) {
memset(dp2, false, sizeof dp2);
for (int i = 1; i <= n; i++) {
dp2[i] = MAXN;
ll s = 0;
for (int j = i; j > 0; j--) {
s += A[j];
if (!(s & mask))
dp2[i] = min(dp2[i], dp2[j - 1]);
}
}
return dp2[n] <= b;
}
inline bool check(ll mask) {
if (a == 1) return check2(mask);
memset(dp, false, sizeof dp);
dp[0][0] = true;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
ll s = 0;
for (int k = i; k > 0; k--) {
s += A[k];
if (!(s & mask))
dp[i][j] |= dp[k - 1][j - 1];
}
}
}
return count(dp[n] + a, dp[n] + b + 1, true);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> A[i];
ll ans = 0, mask = 0;
for (int i = LOG - 1; i >= 0; i--) {
mask ^= (1ll << i);
if (!check(mask)) {
mask ^= (1ll << i);
ans ^= (1ll << i);
}
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |