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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"
const ld PI = 3.1415926535;
const int N = 100+5;
const int M = 7e6 + 1;
int mod = 998244353;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 31;
int mult(int a, int b) {
return a * 1LL * b % mod;
}
int sum(int a, int b) {
if (a + b < 0)
return a + b + mod;
if (a + b >= mod)
return a + b - mod;
return a + b;
}
ll binpow(ll a, ll n) {
if (n == 0)
return 1;
if (n % 2 == 1) {
return binpow(a, n - 1) * a % mod;
} else {
ll b = binpow(a, n / 2);
return b * b % mod;
}
}
int n, A, B, a[N], dp[N][N], pr[N];
bool check(int mask){
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(!dp[i][j])
continue;
for(int nxt = i + 1; nxt <= n; nxt++){
if(((pr[nxt] - pr[i]) | mask) == mask){
//cout << "()() " << nxt << ' ' << j + 1 << " )_)_) ";
dp[nxt][j + 1] = 1;
}
}
}
}
int ans = 0;
for(int gr = A; gr <= B; gr++){
ans |= dp[n][gr];
}
return ans;
}
void solve(){
cin >> n >> A >> B;
for(int i = 1; i <= n; i++){
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
}
int ans = (1LL << 45) - 1;
for(int i = 44; i >= 0; i--){
if(check(ans - (1LL << i))){
ans -= (1LL << i);
}
}
cout << ans << '\n';
}
signed main() {
mispertion;
int t = 1;
//cin >> t;
while(t--){
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... |