이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2005;
int n, a, b;
int y[N], p[N];
void solveTestCase() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) cin >> y[i];
p[0] = y[0];
for (int i = 1; i < n; i++)
p[i] = y[i] + p[i - 1];
int ans = 0;
for (int i = 45; i >= 0; i--) {
int dp[n];
fill(dp, dp + n, 1e14);
int up = ans + (1ll << i);
bool check = y[0] < up;
if ((y[0] & (1ll << i)) == 0)
dp[0] = 1;
for (int j = 1; j < n; j++) {
check = check && y[j] < up;
if (p[j] < up && (p[j] | up) < up + (1ll << i) && (p[j] & (1ll << i)) == 0)
dp[j] = 1;
for (int k = j - 1; k >= 0; k--) {
if ((p[j] - p[k + 1] + y[k + 1]) < up && ((p[j] - p[k + 1] + y[k + 1]) | up) < up + (1ll << i) && ((p[j] - p[k + 1] + y[k + 1]) & (1ll << i)) == 0)
dp[j] = min(dp[j], dp[k] + 1);
}
}
if (!check || dp[n - 1] > b)
ans = up;
}
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
//cin >> test;
while (test--)
solveTestCase();
}
# | 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... |