This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e3 + 1;
bool f[N][N];
ll a[N];
int g[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int A; cin >> A;
int B; cin >> B;
for(int i = 1 ; i <= n ; ++i) {
cin >> a[i];
a[i] += a[i - 1];
}
ll cur_mask = 0;
if (A > 1) {
f[0][0] = 1;
for(int b = 40 ; b >= 0 ; --b) {
for(int i = 1 ; i <= n ; ++i)
for(int j = 1 ; j <= n ; ++j) {
f[i][j] = 0;
for(int k = 0 ; k < i ; ++k) {
ll S = a[i] - a[k];
S >>= b;
S <<= b;
if((S & cur_mask) == S)
f[i][j] |= f[k][j - 1];
}
}
bool ch = 0;
for(int i = A ; i <= B ; ++i)
ch |= f[n][i];
if(!ch) cur_mask |= (1ll << b);
}
}
else {
for(int b = 40 ; b >= 0 ; --b) {
for(int i = 1 ; i <= n ; ++i) {
g[i] = 1e9;
for(int j = 0 ; j < i ; ++j) {
ll S = a[i] - a[j];
S >>= b;
S <<= b;
if ((S & cur_mask) != S)
continue;
g[i] = min(g[i],g[j] + 1);
}
}
if (g[n] > B) cur_mask |= (1ll << b);
}
}
cout << cur_mask << endl;
}
# | 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... |