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 <bits/stdc++.h>
using namespace std;
#define maxn 2010
const int inf = 123456789;
#define ll long long
int N, A, B;
ll nums[maxn];
ll pref = 0LL;
bool dp[maxn][maxn];
//is it possible to end at some guy using exactly some other amount
//use this dp table for N <= 100
//else we just want the minimum number
int mym[maxn];
bool check(ll bit) {
fill(mym, mym+maxn, inf);
mym[0] = 0;
for (int i = 1; i <= N; i++) {
ll csum = 0;
for (int j = i; j >= 1; j--) {
csum += nums[j];
if ( (csum | pref) - pref >= bit) continue;
mym[i] = min(mym[i], mym[j-1]+1);
}
}
return mym[N] <= B;
}
void solve1() {
for (int i = 50; i >= 0; i--) {
ll cbit = 1LL << i;
if (!check(cbit)) {
pref += cbit;
}
}
cout << pref << endl;
}
void solve() {
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> A >> B;
for (int i = 1; i <= N; i++) {
cin >> nums[i];
}
if (A == 1) solve1();
else solve();
}
# | 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... |