이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, A, B;
cin >> n >> A >> B;
vector<int> x(n + 1);
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
long long answer = 0;
if (n <= 100) {
for (int bit = 40; bit >= 0; bit--) {
vector<vector<bool>> dp(B + 1, vector<bool>(n + 1));
dp[0][0] = true;
for (int i = 1; i <= B; i++) {
for (int j = 1; j <= n; j++) {
long long sum = 0;
for (int k = j - 1; k >= 0; k--) {
sum += x[k + 1];
if ((sum >> bit) == (answer >> bit)) {
dp[i][j] = (dp[i][j] | dp[i - 1][k]);
}
}
}
}
bool good = false;
for (int i = A; i <= B; i++) {
good |= dp[i][n];
}
if (!good) {
answer += (1LL << bit);
}
}
} else {
for (int bit = 40; bit >= 0; bit--) {
vector<bool> dp(n + 1);
dp[0] = true;
for (int j = 1; j <= n; j++) {
long long sum = 0;
for (int k = j - 1; k >= 0; k--) {
sum += x[k + 1];
if ((sum >> bit) == (answer >> bit)) {
dp[j] = (dp[j] | dp[k]);
}
}
}
if (dp[n] == false) {
answer += (1LL << bit);
}
}
}
cout << answer;
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... |