/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e3 + 5;
const long long INF = numeric_limits<long long>::max() / 2;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;
int sum[N][N], A[N], ans = 0, rans = 0, n, a, b;
bool check(int a, int b, int p){
return ((a & b) >> p) == 0;
}
void solve4(){
int dp[N][N];
for(int bit = 42; bit >= 0; --bit){
ans ^= (1LL << bit);
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
dp[i][j] = INF;
}
}
for(int i = 1; i <= n; ++i){
if (check(ans, sum[1][i], bit)) dp[1][i] = sum[1][i];
}
int mi = INF;
if (a == 1) mi = dp[1][n];
for(int tme = 2; tme <= b; ++tme){
for(int i = tme; i <= n; ++i){
for(int j = tme; j <= i; ++j){
if (check(ans, sum[j][i], bit)){
dp[tme][i] = min(dp[tme][i], dp[tme - 1][j - 1] | sum[j][i]);
}
}
}
if (tme >= a) mi = min(mi, dp[tme][n]);
}
if (mi == INF){
ans ^= (1LL << bit);
rans ^= (1LL << bit);
}
}
cout << rans;
}
void solve5(){
int dp[N];
for(int bit = 42; bit >= 0; --bit){
ans ^= (1LL << bit);
for(int i = 1; i <= n; ++i) dp[i] = INF;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= i; ++j){
if (check(ans, sum[j][i], bit)) dp[i] = min(dp[i], dp[j - 1] + 1);
}
}
if (dp[n] > b){
ans ^= (1LL << bit);
rans ^= (1LL << bit);
}
}
cout << rans;
}
void solve()
{
cin >> n >> a >> b;
for(int i = 1; i <= n; ++i) cin >> A[i];
for(int i = 1; i <= n; ++i){
for(int j = i; j <= n; ++j){
sum[i][j] = sum[i][j - 1] + A[j];
}
}
if (a == 1){
solve5();
} else {
solve4();
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("codeforces.inp","r",stdin);
// freopen("codeforces.out","w",stdout);
int t = 1; //cin >> t;
while (t--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
15 ms |
31820 KB |
Output is correct |
15 |
Correct |
13 ms |
31848 KB |
Output is correct |
16 |
Correct |
13 ms |
31760 KB |
Output is correct |
17 |
Correct |
13 ms |
31696 KB |
Output is correct |
18 |
Correct |
13 ms |
31828 KB |
Output is correct |
19 |
Correct |
16 ms |
31828 KB |
Output is correct |
20 |
Correct |
13 ms |
31828 KB |
Output is correct |
21 |
Correct |
13 ms |
31776 KB |
Output is correct |
22 |
Correct |
13 ms |
31824 KB |
Output is correct |
23 |
Correct |
13 ms |
31820 KB |
Output is correct |
24 |
Correct |
15 ms |
31804 KB |
Output is correct |
25 |
Correct |
14 ms |
31816 KB |
Output is correct |
26 |
Correct |
14 ms |
31816 KB |
Output is correct |
27 |
Correct |
0 ms |
328 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
13 ms |
31724 KB |
Output is correct |
15 |
Correct |
13 ms |
31796 KB |
Output is correct |
16 |
Correct |
13 ms |
31700 KB |
Output is correct |
17 |
Correct |
13 ms |
31784 KB |
Output is correct |
18 |
Correct |
13 ms |
31720 KB |
Output is correct |
19 |
Correct |
13 ms |
31828 KB |
Output is correct |
20 |
Correct |
13 ms |
31748 KB |
Output is correct |
21 |
Correct |
13 ms |
31828 KB |
Output is correct |
22 |
Correct |
13 ms |
31852 KB |
Output is correct |
23 |
Correct |
15 ms |
31816 KB |
Output is correct |
24 |
Correct |
13 ms |
31876 KB |
Output is correct |
25 |
Correct |
13 ms |
31800 KB |
Output is correct |
26 |
Correct |
13 ms |
31828 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
456 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
584 KB |
Output is correct |
27 |
Correct |
1 ms |
748 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
716 KB |
Output is correct |
30 |
Correct |
2 ms |
724 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
18 ms |
31816 KB |
Output is correct |
15 |
Correct |
14 ms |
31700 KB |
Output is correct |
16 |
Correct |
13 ms |
31696 KB |
Output is correct |
17 |
Correct |
13 ms |
31700 KB |
Output is correct |
18 |
Correct |
13 ms |
31820 KB |
Output is correct |
19 |
Correct |
14 ms |
31812 KB |
Output is correct |
20 |
Correct |
13 ms |
31820 KB |
Output is correct |
21 |
Correct |
13 ms |
31828 KB |
Output is correct |
22 |
Correct |
15 ms |
31828 KB |
Output is correct |
23 |
Correct |
15 ms |
31764 KB |
Output is correct |
24 |
Correct |
14 ms |
31820 KB |
Output is correct |
25 |
Correct |
12 ms |
31772 KB |
Output is correct |
26 |
Correct |
13 ms |
31828 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
328 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
464 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
464 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
2 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
588 KB |
Output is correct |
49 |
Correct |
1 ms |
588 KB |
Output is correct |
50 |
Correct |
1 ms |
724 KB |
Output is correct |
51 |
Correct |
1 ms |
724 KB |
Output is correct |
52 |
Correct |
1 ms |
724 KB |
Output is correct |
53 |
Correct |
2 ms |
724 KB |
Output is correct |
54 |
Correct |
1 ms |
724 KB |
Output is correct |
55 |
Correct |
1 ms |
724 KB |
Output is correct |
56 |
Correct |
1 ms |
464 KB |
Output is correct |
57 |
Correct |
1 ms |
596 KB |
Output is correct |
58 |
Correct |
1 ms |
712 KB |
Output is correct |
59 |
Correct |
1 ms |
720 KB |
Output is correct |
60 |
Correct |
1 ms |
724 KB |
Output is correct |
61 |
Correct |
1 ms |
724 KB |
Output is correct |
62 |
Correct |
1 ms |
724 KB |
Output is correct |
63 |
Correct |
1 ms |
724 KB |
Output is correct |
64 |
Correct |
26 ms |
32084 KB |
Output is correct |
65 |
Correct |
15 ms |
31944 KB |
Output is correct |
66 |
Correct |
15 ms |
32004 KB |
Output is correct |
67 |
Correct |
16 ms |
32136 KB |
Output is correct |
68 |
Correct |
22 ms |
32200 KB |
Output is correct |
69 |
Correct |
26 ms |
32192 KB |
Output is correct |
70 |
Correct |
25 ms |
32208 KB |
Output is correct |
71 |
Correct |
13 ms |
32200 KB |
Output is correct |
72 |
Correct |
26 ms |
32212 KB |
Output is correct |
73 |
Correct |
25 ms |
32240 KB |
Output is correct |
74 |
Correct |
26 ms |
32140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
452 KB |
Output is correct |
34 |
Correct |
1 ms |
456 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
1 ms |
724 KB |
Output is correct |
38 |
Correct |
2 ms |
712 KB |
Output is correct |
39 |
Correct |
1 ms |
720 KB |
Output is correct |
40 |
Correct |
1 ms |
724 KB |
Output is correct |
41 |
Correct |
1 ms |
716 KB |
Output is correct |
42 |
Correct |
2 ms |
724 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
596 KB |
Output is correct |
45 |
Correct |
1 ms |
724 KB |
Output is correct |
46 |
Correct |
2 ms |
724 KB |
Output is correct |
47 |
Correct |
1 ms |
724 KB |
Output is correct |
48 |
Correct |
1 ms |
716 KB |
Output is correct |
49 |
Correct |
2 ms |
724 KB |
Output is correct |
50 |
Correct |
1 ms |
724 KB |
Output is correct |
51 |
Correct |
1 ms |
724 KB |
Output is correct |
52 |
Correct |
13 ms |
3924 KB |
Output is correct |
53 |
Correct |
20 ms |
5540 KB |
Output is correct |
54 |
Correct |
39 ms |
8148 KB |
Output is correct |
55 |
Correct |
42 ms |
8252 KB |
Output is correct |
56 |
Correct |
539 ms |
23036 KB |
Output is correct |
57 |
Correct |
495 ms |
23056 KB |
Output is correct |
58 |
Correct |
495 ms |
23036 KB |
Output is correct |
59 |
Correct |
572 ms |
23040 KB |
Output is correct |
60 |
Correct |
537 ms |
23040 KB |
Output is correct |
61 |
Correct |
1 ms |
724 KB |
Output is correct |
62 |
Correct |
20 ms |
5460 KB |
Output is correct |
63 |
Correct |
40 ms |
8260 KB |
Output is correct |
64 |
Correct |
49 ms |
8276 KB |
Output is correct |
65 |
Correct |
148 ms |
13696 KB |
Output is correct |
66 |
Correct |
367 ms |
19064 KB |
Output is correct |
67 |
Correct |
551 ms |
23044 KB |
Output is correct |
68 |
Correct |
560 ms |
23036 KB |
Output is correct |
69 |
Correct |
541 ms |
23032 KB |
Output is correct |