이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) cerr << #x << ": " << x << endl;
const int MAX_N = 2000 + 5;
const int MAX_X = 20;
const int INF = 1e9;
int a[MAX_N];
int dp[MAX_N][MAX_N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, l, r;
cin >> n >> l >> r;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
// minimize (a1 + a2 + ... + a_(k - 1)) | (a_k + a_(k + 1) + ...) | ...
// IMPORTANT NOTE: IN LAST GROUP n = 2000 and l = 1
// maybe greedy bit by bit? minimize first, then second, ...
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < MAX_N; ++j) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
int s = 0;
for (int j = i; j > 0; --j) {
s += a[j];
for (int x = 0; x <= j * MAX_X + 5; ++x) {
dp[i][s | x] = min(dp[i][s | x], dp[j - 1][x] + 1);
}
}
}
int ans = INF;
for (int x = 0; x < MAX_N; ++x) {
if (dp[n][x] <= r) {
ans = min(ans, x);
}
}
cout << ans << '\n';
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
| # | 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... |