이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) (v).begin(), (v).end()
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, A, B;
cin >> n >> A >> B;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
if (A == 1) {
ll ans = (1LL << 50) - 1;
for (int z = 49; z >= 0; z--) {
ans -= (1LL << z);
ll sm = 0;
vector<int> dp(n, INT_MAX);
for (int i = 0; i < n; i++) {
sm += a[i];
if ((ans & sm) == sm) dp[i] = 0;
ll sm = 0;
for (int k = i; k > 0; k--) {
sm += a[k];
if (dp[k - 1] != INT_MAX && (ans & sm) == sm) dp[i] = min(dp[i], dp[k - 1] + 1);
}
}
if (B <= dp[n - 1]) ans += 1LL << z;
}
return cout << ans, 0;
}
ll ans = (1LL << 50) - 1;
for (int z = 49; z >= 0; z--) {
ans -= (1LL << z);
ll sm = 0;
vector<vector<bool>> dp(n, vector<bool>(n));
for (int i = 0; i < n; i++) {
sm += a[i];
if ((ans & sm) == sm) dp[i][0] = true;
for (int j = 1; j < n; j++) {
ll sm = 0;
for (int k = i; k > 0; k--) {
sm += a[k];
if (dp[k - 1][j - 1] && (ans & sm) == sm) dp[i][j] = true;
}
}
}
if (!count(dp[n - 1].begin() + A - 1, dp[n - 1].begin() + B, true)) ans += 1LL << z;
}
cout << ans;
}
# | 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... |