This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Muallif: Azimjon Mehmonali o'g'li
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = (1ll << 35) - 1;
const int N = 2111;
const int K = 2111;
int n, k, a, b;
int y[N], p[N], dp[K][N], pp[K][N];
bool check(int mask, int cand) {
for (int i = 0; i < 60; i++) {
if (!(mask & (1ll << i)) && (cand & (1ll << i))) return false;
}
return true;
}
bool can(int mask) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
dp[0][i] = check(mask, p[i]);
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
dp[k][i] |= dp[k - 1][j] && check(mask, p[i] - p[j]);
}
}
}
bool fl = 0;
for (int i = a; i <= b; i++) {
fl |= dp[i - 1][n];
}
return fl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> y[i];
p[i] = p[i - 1] + y[i];
}
int nt = (1ll << 61) - 1;
for (int i = 60; i >= 0; i--) {
if (can(nt - (1ll << i))) {
nt -= (1ll << i);
}
}
cout << nt << endl;
return 0;
}
# | 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... |