이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;
const int N = 2e3 + 5;
int n, L, R;
ll a[N];
ll ans;
bool dp1[N][N];
int dp2[N];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("KEK.inp", "r", stdin);
// freopen("KEK.out", "w", stdout);
cin >> n >> L >> R;
ForE(i, 1, n){
cin >> a[i]; a[i] += a[i - 1];
}
if (n <= 100){
FordE(bit, 36, 0){
ll tans = ans + (1ll << bit) - 1;
ForE(i, 1, n){
ForE(j, 1, R){
dp1[i][j] = 0;
}
}
dp1[0][0] = 1;
ForE(i, 1, n){
ForE(j, 1, R){
ForE(ti, 1, i){
ll sum = a[i] - a[ti - 1];
if ((tans & sum) == sum){
dp1[i][j] |= dp1[ti - 1][j - 1];
}
}
}
}
bool ck = 0;
ForE(j, L, R){
ck |= dp1[n][j];
}
if (!ck){
ans |= (1ll << bit);
}
}
cout << ans << endl;
return 0;
}
assert(L == 1);
FordE(bit, 36, 0){
ll tans = ans + (1ll << bit) - 1;
ForE(i, 1, n){
dp2[i] = N;
}
dp2[0] = 0;
ForE(i, 1, n){
ForE(ti, 1, i){
ll sum = a[i] - a[ti - 1];
if ((tans & sum) == sum){
dp2[i] = min(dp2[i], dp2[ti - 1] + 1);
}
}
}
if (dp2[n] > R){
ans |= (1ll << bit);
}
}
cout << ans << endl;
}
/*
n so, phan thanh x (a <= x <= b) khoang sao cho or cua tong la be nhat
nhieu kha nang sub 4 va sub 5 giai khac nhau vi sub 5 co a = 1 ????
xet bit cao nhat xong roi kiem tra xem co dat duoc tong do hay ko?
dp[i][j] = chekc xem phan duoc thanh j doan co or la submask cua X hay ko
update n^2?
n^3 * 30 la xong sub 1-4
a = 1 thi
xet xem so doan duoc phan it nhat la bao nhieu a
==================================================+
INPUT: |
--------------------------------------------------|
6 1 3
8 1 2 1 5 4
--------------------------------------------------|
==================================================+
OUTPUT: |
--------------------------------------------------|
11
--------------------------------------------------|
==================================================+
*/
# | 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... |