This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, a, b;
cin >> n >> a >> b;
vector <int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
vector <ll> pref(n + 1);
for (int i = 0; i < n; ++i) {
pref[i + 1] = pref[i] + v[i];
}
auto get = [&] (int l, int r) {
return pref[r + 1] - pref[l];
};
if (n <= 200) {
auto can = [&] (ll mask) {
vector <vector <int>> dp(n + 1, vector <int> (n + 1));
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = i; k < n; ++k) {
ll sm = get(i, k);
if ((sm & mask) == 0) {
dp[k + 1][j + 1] |= dp[i][j];
}
}
}
}
bool ok = false;
for (int x = a; x <= b; ++x) {
ok |= dp[n][x];
}
return ok;
};
ll mask = 0;
ll ans = 0;
for (int b = 60; b >= 0; --b) {
if (can(mask + (1LL << b))) {
mask += (1LL << b);
} else {
ans += (1LL << b);
}
}
cout << ans << '\n';
} else {
assert(false);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |