/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int ,int > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 2100;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n;
int a[maxn];
int l , r;
void sub1(){
ll ans = 1e18;
for(int i = 0 ; i < (1 << (n - 1)) ; i ++)
if(__builtin_popcount(i)+1 >= l and __builtin_popcount(i)+1 <= r){
vector < ll > vec;
vec.clear();
vec.pb(0);
for(int j = 0 ; j < n ; j ++){
vec.back()+=a[j];
if(i & (1 << j))
vec.pb(0);
}
ll orr = 0;
for(auto x : vec)
orr|=x;
ans = min(ans , orr);
}
dokme(ans);
}
int mark[60][60][600];
ll ans;
void dfs(int i , int k , int Or){
if(i == n and k >= l and k <= r)
ans = min(ans , (ll)Or);
mark[i][k][Or] = 1;
int sum = 0;
for(int j = i+1 ; j <= n ; j ++){
sum += a[j - 1];
if(!mark[j][k+1][Or|sum])
dfs(j, k + 1 , Or | sum);
}
}
void sub2(){
ans = 1e9;
dfs(0 , 0 , 0);
dokme(ans);
}
ll dp[maxn];
ll solve(){
ms(dp , 63), ans = dp[0];
for(int i = 63 ; i >= 0 ; i --){
ms(dp , 63), dp[0] = 0;
for(int j = 1 ; j <= n ; j ++){
ll sum = 0;
for(int k = j ; k <= n ; k ++){
sum += a[k-1];
if((sum | (ans - (1LL << ll(i)))) == (ans - (1LL << ll(i))))
dp[k+1] = min(dp[k+1] , dp[j] + 1);
}
}
if(dp[n] <= r)
ans -= (1LL << ll(i));
}
return(ans);
}
int32_t main(){
migmig;
cin >> n >> l >> r;
for(int i = 0 ; i < n ; i ++)
cin >> a[i];
cout << solve();
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |