이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, A, B;
int arr[N];
long long sum[N];
namespace Task1 {
bool f[N][N];
void calDP(long long mask) {
f[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
f[i][j] = 0;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
for (int k = 0; k < i; ++k) {
if ((sum[i] - sum[k]) & mask) continue;
f[i][j] |= f[k][j - 1];
}
}
}
}
void solve() {
long long mask = 0, res = 0;
for (int i = 45; i >= 0; --i) {
mask ^= (1LL << i);
calDP(mask);
bool found = 0;
for (int j = A; j <= B; ++j) found |= f[n][j];
if (!found) {
mask ^= (1LL << i), res += 1LL << i;
}
}
cout << res;
}
}
namespace Task2 {
const int INF = 1e9;
int f[N];
void calDP(long long mask) {
f[0] = 0;
for (int i = 1; i <= n; ++i) {
f[i] = INF;
for (int j = 0; j < i; ++j) {
if ((sum[i] - sum[j]) & mask) continue;
f[i] = min(f[i], f[j] + 1);
}
}
}
void solve() {
long long mask = 0, res = 0;
for (int i = 45; i >= 0; --i) {
mask ^= (1LL << i);
calDP(mask);
bool found = f[n] <= B;
if (!found) {
mask ^= (1LL << i), res += 1LL << i;
}
}
cout << res << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> A >> B;
for (int i = 1; i <= n; ++i) cin >> arr[i];
for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + arr[i];
if (n <= 100)
Task1::solve();
else
Task2::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... |