이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN1 = 100;
bool dp[MAXN1+1][MAXN1];
int n, a, b;
int vals[MAXN1];
ll cur = 0;
int bit;
bool works(ll sum) {
ll sumshift = sum >> bit;
ll curshift = cur >> bit;
return (curshift&sumshift) == sumshift;
}
bool possible() {
for (int i = n; i >= 0; i--) {
for (int j = 0; j < n; j++) {
dp[i][j] = 0;
if (i == n) {
dp[i][j] = 1;
continue;
}
if (j > n-i) {
dp[i][j] = dp[i][n-i];
continue;
}
if (j == 0) {
continue;
}
ll s = 0;
for (int next = i+1; next <= n; next++) {
s += vals[next-1];
if (dp[next][j-1] && works(s)) {
dp[i][j] = 1;
break;
}
}
}
}
for (int i = a; i <= b; i++)
if (dp[0][i]) return 1;
return 0;
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) {
cin >> vals[i];
cur += vals[i];
}
bit = floor(log2(cur));
cur = 0;
while (bit >= 0) {
if (!possible()) { // possible to avoid
cur += (1LL << bit);
}
bit--;
}
cout << cur << "\n";
}
# | 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... |