#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
sculpture.cpp: In function 'void sub4::solution()':
sculpture.cpp:76:18: warning: unused variable 'ok' [-Wunused-variable]
76 | bool ok = 0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
356 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
360 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
472 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
472 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
0 ms |
476 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
360 KB |
Output is correct |
18 |
Correct |
1 ms |
360 KB |
Output is correct |
19 |
Correct |
0 ms |
360 KB |
Output is correct |
20 |
Correct |
0 ms |
360 KB |
Output is correct |
21 |
Correct |
0 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
568 KB |
Output is correct |
32 |
Correct |
3 ms |
568 KB |
Output is correct |
33 |
Correct |
3 ms |
472 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
572 KB |
Output is correct |
36 |
Correct |
3 ms |
572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
11 ms |
632 KB |
Output is correct |
27 |
Correct |
18 ms |
2652 KB |
Output is correct |
28 |
Correct |
24 ms |
604 KB |
Output is correct |
29 |
Correct |
24 ms |
664 KB |
Output is correct |
30 |
Correct |
25 ms |
600 KB |
Output is correct |
31 |
Correct |
25 ms |
2696 KB |
Output is correct |
32 |
Correct |
23 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
360 KB |
Output is correct |
13 |
Correct |
1 ms |
360 KB |
Output is correct |
14 |
Correct |
1 ms |
360 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
360 KB |
Output is correct |
17 |
Correct |
0 ms |
360 KB |
Output is correct |
18 |
Correct |
0 ms |
360 KB |
Output is correct |
19 |
Correct |
0 ms |
360 KB |
Output is correct |
20 |
Correct |
0 ms |
480 KB |
Output is correct |
21 |
Correct |
1 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
360 KB |
Output is correct |
23 |
Correct |
1 ms |
360 KB |
Output is correct |
24 |
Correct |
1 ms |
360 KB |
Output is correct |
25 |
Correct |
0 ms |
360 KB |
Output is correct |
26 |
Correct |
0 ms |
480 KB |
Output is correct |
27 |
Correct |
0 ms |
360 KB |
Output is correct |
28 |
Correct |
0 ms |
360 KB |
Output is correct |
29 |
Correct |
1 ms |
360 KB |
Output is correct |
30 |
Correct |
0 ms |
360 KB |
Output is correct |
31 |
Correct |
0 ms |
360 KB |
Output is correct |
32 |
Correct |
0 ms |
360 KB |
Output is correct |
33 |
Correct |
0 ms |
360 KB |
Output is correct |
34 |
Correct |
0 ms |
360 KB |
Output is correct |
35 |
Correct |
0 ms |
360 KB |
Output is correct |
36 |
Correct |
1 ms |
360 KB |
Output is correct |
37 |
Correct |
1 ms |
360 KB |
Output is correct |
38 |
Correct |
1 ms |
360 KB |
Output is correct |
39 |
Correct |
1 ms |
360 KB |
Output is correct |
40 |
Correct |
2 ms |
360 KB |
Output is correct |
41 |
Correct |
3 ms |
360 KB |
Output is correct |
42 |
Correct |
3 ms |
360 KB |
Output is correct |
43 |
Correct |
3 ms |
360 KB |
Output is correct |
44 |
Correct |
3 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
568 KB |
Output is correct |
46 |
Correct |
3 ms |
464 KB |
Output is correct |
47 |
Correct |
3 ms |
348 KB |
Output is correct |
48 |
Correct |
7 ms |
344 KB |
Output is correct |
49 |
Correct |
11 ms |
600 KB |
Output is correct |
50 |
Correct |
19 ms |
2904 KB |
Output is correct |
51 |
Correct |
23 ms |
676 KB |
Output is correct |
52 |
Correct |
26 ms |
604 KB |
Output is correct |
53 |
Correct |
24 ms |
604 KB |
Output is correct |
54 |
Correct |
25 ms |
2692 KB |
Output is correct |
55 |
Correct |
23 ms |
604 KB |
Output is correct |
56 |
Correct |
2 ms |
572 KB |
Output is correct |
57 |
Correct |
7 ms |
624 KB |
Output is correct |
58 |
Correct |
12 ms |
604 KB |
Output is correct |
59 |
Correct |
13 ms |
676 KB |
Output is correct |
60 |
Correct |
13 ms |
2652 KB |
Output is correct |
61 |
Correct |
13 ms |
684 KB |
Output is correct |
62 |
Correct |
15 ms |
2648 KB |
Output is correct |
63 |
Correct |
17 ms |
604 KB |
Output is correct |
64 |
Correct |
20 ms |
604 KB |
Output is correct |
65 |
Correct |
2 ms |
348 KB |
Output is correct |
66 |
Correct |
4 ms |
348 KB |
Output is correct |
67 |
Correct |
7 ms |
604 KB |
Output is correct |
68 |
Correct |
10 ms |
2696 KB |
Output is correct |
69 |
Correct |
14 ms |
628 KB |
Output is correct |
70 |
Correct |
13 ms |
672 KB |
Output is correct |
71 |
Correct |
13 ms |
604 KB |
Output is correct |
72 |
Correct |
15 ms |
672 KB |
Output is correct |
73 |
Correct |
15 ms |
676 KB |
Output is correct |
74 |
Correct |
15 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
388 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
6 ms |
604 KB |
Output is correct |
36 |
Correct |
11 ms |
604 KB |
Output is correct |
37 |
Correct |
18 ms |
2648 KB |
Output is correct |
38 |
Correct |
24 ms |
2652 KB |
Output is correct |
39 |
Correct |
23 ms |
2652 KB |
Output is correct |
40 |
Correct |
26 ms |
2692 KB |
Output is correct |
41 |
Correct |
26 ms |
600 KB |
Output is correct |
42 |
Correct |
25 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
7 ms |
604 KB |
Output is correct |
45 |
Correct |
11 ms |
604 KB |
Output is correct |
46 |
Correct |
14 ms |
676 KB |
Output is correct |
47 |
Correct |
13 ms |
600 KB |
Output is correct |
48 |
Correct |
13 ms |
2652 KB |
Output is correct |
49 |
Correct |
15 ms |
672 KB |
Output is correct |
50 |
Correct |
22 ms |
604 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
6 ms |
348 KB |
Output is correct |
53 |
Correct |
9 ms |
348 KB |
Output is correct |
54 |
Correct |
16 ms |
348 KB |
Output is correct |
55 |
Correct |
16 ms |
748 KB |
Output is correct |
56 |
Correct |
58 ms |
344 KB |
Output is correct |
57 |
Correct |
57 ms |
348 KB |
Output is correct |
58 |
Correct |
74 ms |
344 KB |
Output is correct |
59 |
Correct |
68 ms |
480 KB |
Output is correct |
60 |
Correct |
59 ms |
344 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
9 ms |
348 KB |
Output is correct |
63 |
Correct |
17 ms |
344 KB |
Output is correct |
64 |
Correct |
15 ms |
492 KB |
Output is correct |
65 |
Correct |
29 ms |
348 KB |
Output is correct |
66 |
Correct |
56 ms |
480 KB |
Output is correct |
67 |
Correct |
75 ms |
496 KB |
Output is correct |
68 |
Correct |
61 ms |
480 KB |
Output is correct |
69 |
Correct |
57 ms |
348 KB |
Output is correct |