This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 2e3 + 1;
int n, a, b;
int y[maxn];
int check(ll s) {
if(n < 200){
bool dp[n][n + 2];
memset(dp, 0, sizeof dp);
for(int i = 0; i < n; i++){
ll t = 0;
for(int j = i; j >= 0; j--){
t += y[j];
if(!(s & t)){
if(j == 0)dp[i][1] = 1;
else {
for(int o = 0; o <= n; o++){
if(dp[j - 1][o])dp[i][o + 1] = 1;
}
}
}
}
}
for(int i = a; i <= b; i++){
if(dp[n - 1][i])return 0;
}
return 1;
}
int dp[n];
for(int i = 0; i < n; i++){
dp[i] = maxn;
ll t = 0;
for(int j = i; j >= 0; j--){
t += y[j];
if(!(s & t)){
if(j == 0)dp[i] = 1;
else dp[i] = min(dp[i], dp[j - 1] + 1);
}
}
}
return (dp[n - 1] > b);
}
void solve() {
cin >> n >> a >> b;
for(int i = 0; i < n; i++){
cin >> y[i];
}
ll s = 0, ans = 0;
for(int i = 40; i >= 0; i--){
s += (1ll << i);
if(check(s))s -= (1ll << i), ans += (1ll << i);
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# | 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... |