이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
const int N = 2005;
ll p[N];
ll sum(int l, int r) {
return p[r] - (l ? p[l - 1] : 0);
}
//dp[index][OR][number of subarrays] = 1 if possible to obtain such partition
int dp[N][N];
ll excluded;
bool check(ll k, int n, vector<ll>& a, int A, int B) {
for(int i = 0;i < N; ++i) for(int j = 0;j < N; ++j) dp[i][j] = 0;
dp[0][0] = 1;
for(int i = 1; i <= n; ++i) {
for(int j = 0;j < i; ++j) {
ll s = sum(j, i - 1);
if((s & excluded) || (s & (1LL << k))) continue;
for(int x = 0;x < n; ++x) {
dp[i][x + 1] |= dp[j][x];
}
}
}
for(int j = A; j <= B; ++j) {
if(dp[n][j]) return true;
}
return false;
}
void solve() {
ll n, A, B;
cin >> n >> A >> B;
vector<ll> a(n);
for(int i = 0;i < n; ++i) {
cin >> a[i];
p[i] = (i ? p[i - 1] : 0) + a[i];
}
ll ans = 0;
for(ll pw = 62; pw >= 0; --pw) {
if(check(pw, n, a, A, B)) {
excluded += (1LL << pw);
} else {
ans += (1LL << pw);
}
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
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... |