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>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define iter(id, v) for(auto id : v)
#define fs first
#define se second
#define MP make_pair
#define pb push_back
#define bit(msk, i) ((msk >> i) & 1)
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 2e3 + 7;
const int Mod = 1e9 + 2022; ///loonf mod sai
const int INF = 1e9;
const ll BASE = 137;
const int szBL = 320;
ll n, A, B;
int a[N];
namespace sub3 {
bool dp[N][N];
void solution() {
ll Ans = 0;
reb (t, 40, 0) {
ll Mask = Ans | ((1LL << t) - 1);
dp[0][0] = 1;
rep (i, 1, n)
rep (j, 1, i) {
ll sum = 0;
dp[i][j] = 0;
reb (k, i, 1) {
sum += a[k];
if ((Mask & sum) == sum) {
dp[i][j] |= dp[k - 1][j - 1];
}
}
}
bool ok = 0;
rep (k, A, B) {
ok |= dp[n][k];
}
if (!ok) Ans |= (1LL << t);
}
cout << Ans <<"\n";
}
}
namespace sub4 {
int dp[N];
void solution() {
ll Ans = 0;
reb (t, 40, 0) {
ll Mask = Ans | ((1LL << t) - 1);
dp[0] = 0;
rep (i, 1, n) {
dp[i] = INF;
ll sum = 0;
reb (k, i, 1) {
sum += a[k];
if ((Mask & sum) == sum) dp[i] = min(dp[k - 1] + 1, dp[i]);
}
}
bool ok = 0;
if (dp[n] > B) Ans |= (1LL << t);
}
cout << Ans <<"\n";
}
}
void solution() {
cin >> n >> A >> B;
rep (i, 1, n) cin >> a[i];
if (n <= 100) sub3 :: solution();
else
sub4 :: solution();
}
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
// file("c");
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
no bug +8
chu y break hay return se lam hong logic
xet transition cua i va i + 1
construct ket qua
chu y truong hop : KHONG CO GI
ko làm được
hướng 1: đổi hướng làm
hướng 2: đưa ra nhận xét
tim mo hinh bai toan sau khi doc de
trung ten bien trong ham gan nhat co the dan den sai
10 7 3
6 5
3 6
9 3
8 3
7 8
7 1
2 5
7 10
8 4
9 4 10 1 10 7 6
4 4
1 3
6 7
*/
Compilation message (stderr)
sculpture.cpp: In function 'void sub4::solution()':
sculpture.cpp:76:18: warning: unused variable 'ok' [-Wunused-variable]
76 | bool ok = 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... |