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[N];
bool check(int mask, int cand) { return (!(~mask & cand)); }
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;
}
bool cann(int mask) {
for (int i = 0; i < N; i++)
pp[i] = INF;
pp[1] = 0;
for (int i = 1; i <= n; i++) {
if (pp[i] >= INF) continue;
for (int j = i; j <= n; j++) {
if (check(mask, p[j] - p[i - 1])) {
pp[j + 1] = min(pp[j + 1], pp[i] + 1);
}
}
}
return pp[n + 1] <= b;
}
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 << 51) - 1;
for (int i = 50; i >= 0; i--) {
if (a == 1) {
if (cann(nt - (1ll << i))) {
nt -= (1ll << i);
}
} else {
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... |