이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 9;
const ll LOGN = 21;
const ll MAXN = 3000;
vector<ll> arr;
ll pref[MAXN], N, A, B;
pair<ll,ll> dp[MAXN];
bool check(ll mid) {
dp[0] = {0, 0};
for (int i = 1; i < MAXN; i++)
dp[i] = {1e12, -1e12};
for (int i = 1; i <= N; i++) {
for (int j = i-1; j >= 0; j--) {
if ((mid | (pref[i] - pref[j])) == mid)
dp[i] = {min(dp[i].f, dp[j].f + 1), max(dp[i].s, dp[j].s + 1)};
}
}
return (B >= dp[N].f && A <= dp[N].s);
}
void solve1() {
ll ans = (1LL << 35) - 1;
for (int bit = 34; bit >= 0; bit--) {
bool ch = check(ans ^ (1LL << bit));
if (ch)
ans ^= (1LL << bit);
}
cout << ans << "\n";
}
void solve2() {
}
int main() {
cin >> N >> A >> B;
arr = vector<ll>(N+1);
for (int i = 1; i <= N; i++) {
cin >> arr[i];
pref[i] = pref[i-1] + arr[i];
}
if (N > 100)
solve1();
else
solve2();
}
# | 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... |