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>
#include<fstream>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 2e5 + 5, mxd = 250 * 250, sq = 100, mxv = 5e4 + 1, mxq = 2e6 + 5, T = 1000;
//const int base = (1 <<18);
const ll inf = 2e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, a, b;
bool dp[205][205];
ll pref[2005], x[2005];
int dp2[2005];
ll ans = 0;
bool check(ll v){
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
for(int took = 1; took <= n; took++){
for(int j = i - 1; j >= 0; j--){
if(((pref[i] - pref[j]) | v) == v){
dp[i][took] |= dp[j][took - 1];
}
}
}
}
for(int i = a; i <= b; i++){
if(dp[n][i])return(1);
}
return(0);
}
bool check2(ll v){
for(int i = 1; i <= n; i++)dp2[i] = inf;
dp2[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = i - 1; j >= 0; j--){
if(((pref[i] - pref[j]) | v) == v){
dp2[i] = min(dp2[i], dp2[j] + 1);
}
}
}
return(dp2[n] <= b);
}
void solve(){
cin >> n >> a >> b;
for(int i = 1; i <= n; i++){
cin >> x[i]; pref[i] = pref[i - 1] + x[i];
}
for(int i = 40; i >= 0; i--){
if(a > 1){
if(!check(ans + (1LL << i) - 1)){
ans += (1LL << i);
}
}else{
if(!check2(ans + (1LL << i) - 1)){
ans += (1LL << i);
}
}
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("TREEGCD.inp", "r", stdin);
//freopen("TREEGCD.out", "w", stdout);
int tt; tt = 1;
while(tt--){
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... |