이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SOLVE int t; cin >> t; while (t--) solve();
#define int long long
using namespace std;
const int N = 2e3 + 228;
int good[N][N];
long long pr[N];
bool check(int n, int R, int ind) {
vector<int> dp(n + 1, n + 228);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < i; ++j) {
if (i == n) {
//
}
if (!good[j][i - 1] && !((pr[i] - pr[j]) & (1 << ind))) {
dp[i] = min(dp[i], dp[j] + 1);
}
}
}
return dp[n] <= R;
}
signed main() {
#ifdef DEBUG
freopen("main/in.txt", "r", stdin);
#endif
#ifndef LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
int n, L, R;
cin >> n >> L >> R;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
pr[i + 1] = pr[i] + a[i];
}
int ans = 0;
for (int i = 30; i >= 0; --i) {
if (!check(n, R, i)) {
ans += (1 << i);
} else {
for (int j = 0; j < n; ++j) {
for (int k = 0; k <= j; ++k) {
if ((pr[j + 1] - pr[k]) & (1 << i)) {
good[k][j] = 1;
}
}
}
}
}
cout << ans << '\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... |