#include <bits/stdc++.h>
using namespace std;
#define maxn 2010
const int inf = 123456789;
#define ll long long
int N, A, B;
ll nums[maxn];
ll pref = 0LL;
bool dp[maxn][maxn];
//is it possible to end at some guy using exactly some other amount
//use this dp table for N <= 100
//else we just want the minimum number
int mym[maxn];
bool check(ll bit) {
fill(mym, mym+maxn, inf);
mym[0] = 0;
for (int i = 1; i <= N; i++) {
ll csum = 0;
for (int j = i; j >= 1; j--) {
csum += nums[j];
if ( (csum | pref) - pref >= bit) continue;
mym[i] = min(mym[i], mym[j-1]+1);
}
}
return mym[N] <= B;
}
void solve1() {
for (int i = 50; i >= 0; i--) {
ll cbit = 1LL << i;
if (!check(cbit)) {
pref += cbit;
}
}
cout << pref << endl;
}
void solve() {
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> A >> B;
for (int i = 1; i <= N; i++) {
cin >> nums[i];
}
if (A == 1) solve1();
else solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
580 KB |
Output is correct |
3 |
Correct |
2 ms |
624 KB |
Output is correct |
4 |
Correct |
2 ms |
648 KB |
Output is correct |
5 |
Correct |
2 ms |
648 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
2 ms |
756 KB |
Output is correct |
8 |
Correct |
2 ms |
792 KB |
Output is correct |
9 |
Correct |
2 ms |
792 KB |
Output is correct |
10 |
Correct |
2 ms |
792 KB |
Output is correct |
11 |
Correct |
2 ms |
792 KB |
Output is correct |
12 |
Correct |
2 ms |
792 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Incorrect |
2 ms |
792 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
792 KB |
Output is correct |
2 |
Correct |
2 ms |
792 KB |
Output is correct |
3 |
Correct |
2 ms |
800 KB |
Output is correct |
4 |
Correct |
2 ms |
804 KB |
Output is correct |
5 |
Correct |
2 ms |
808 KB |
Output is correct |
6 |
Correct |
2 ms |
812 KB |
Output is correct |
7 |
Correct |
2 ms |
816 KB |
Output is correct |
8 |
Correct |
2 ms |
820 KB |
Output is correct |
9 |
Correct |
2 ms |
824 KB |
Output is correct |
10 |
Correct |
2 ms |
828 KB |
Output is correct |
11 |
Correct |
2 ms |
832 KB |
Output is correct |
12 |
Correct |
2 ms |
832 KB |
Output is correct |
13 |
Correct |
2 ms |
840 KB |
Output is correct |
14 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
848 KB |
Output is correct |
2 |
Correct |
2 ms |
852 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
864 KB |
Output is correct |
6 |
Correct |
2 ms |
868 KB |
Output is correct |
7 |
Correct |
2 ms |
872 KB |
Output is correct |
8 |
Correct |
2 ms |
876 KB |
Output is correct |
9 |
Correct |
2 ms |
880 KB |
Output is correct |
10 |
Correct |
2 ms |
880 KB |
Output is correct |
11 |
Correct |
2 ms |
880 KB |
Output is correct |
12 |
Correct |
2 ms |
904 KB |
Output is correct |
13 |
Correct |
2 ms |
904 KB |
Output is correct |
14 |
Correct |
2 ms |
904 KB |
Output is correct |
15 |
Correct |
2 ms |
904 KB |
Output is correct |
16 |
Correct |
2 ms |
904 KB |
Output is correct |
17 |
Correct |
2 ms |
904 KB |
Output is correct |
18 |
Correct |
2 ms |
1040 KB |
Output is correct |
19 |
Correct |
2 ms |
1040 KB |
Output is correct |
20 |
Correct |
3 ms |
1040 KB |
Output is correct |
21 |
Correct |
2 ms |
1040 KB |
Output is correct |
22 |
Correct |
2 ms |
1040 KB |
Output is correct |
23 |
Correct |
2 ms |
1040 KB |
Output is correct |
24 |
Correct |
2 ms |
1040 KB |
Output is correct |
25 |
Correct |
2 ms |
1040 KB |
Output is correct |
26 |
Correct |
3 ms |
1044 KB |
Output is correct |
27 |
Correct |
3 ms |
1044 KB |
Output is correct |
28 |
Correct |
3 ms |
1044 KB |
Output is correct |
29 |
Correct |
3 ms |
1044 KB |
Output is correct |
30 |
Correct |
3 ms |
1044 KB |
Output is correct |
31 |
Correct |
3 ms |
1044 KB |
Output is correct |
32 |
Correct |
3 ms |
1044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1044 KB |
Output is correct |
2 |
Correct |
2 ms |
1044 KB |
Output is correct |
3 |
Correct |
2 ms |
1044 KB |
Output is correct |
4 |
Correct |
2 ms |
1044 KB |
Output is correct |
5 |
Correct |
2 ms |
1044 KB |
Output is correct |
6 |
Correct |
2 ms |
1044 KB |
Output is correct |
7 |
Correct |
2 ms |
1044 KB |
Output is correct |
8 |
Correct |
2 ms |
1044 KB |
Output is correct |
9 |
Correct |
3 ms |
1044 KB |
Output is correct |
10 |
Correct |
2 ms |
1044 KB |
Output is correct |
11 |
Correct |
3 ms |
1044 KB |
Output is correct |
12 |
Correct |
3 ms |
1044 KB |
Output is correct |
13 |
Correct |
2 ms |
1044 KB |
Output is correct |
14 |
Incorrect |
2 ms |
1044 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1044 KB |
Output is correct |
2 |
Correct |
2 ms |
1044 KB |
Output is correct |
3 |
Correct |
2 ms |
1044 KB |
Output is correct |
4 |
Correct |
2 ms |
1052 KB |
Output is correct |
5 |
Correct |
2 ms |
1056 KB |
Output is correct |
6 |
Correct |
2 ms |
1060 KB |
Output is correct |
7 |
Correct |
2 ms |
1064 KB |
Output is correct |
8 |
Correct |
3 ms |
1068 KB |
Output is correct |
9 |
Correct |
2 ms |
1072 KB |
Output is correct |
10 |
Correct |
2 ms |
1076 KB |
Output is correct |
11 |
Correct |
2 ms |
1080 KB |
Output is correct |
12 |
Correct |
2 ms |
1084 KB |
Output is correct |
13 |
Correct |
2 ms |
1088 KB |
Output is correct |
14 |
Correct |
3 ms |
1092 KB |
Output is correct |
15 |
Correct |
3 ms |
1096 KB |
Output is correct |
16 |
Correct |
2 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
2 ms |
1108 KB |
Output is correct |
19 |
Correct |
2 ms |
1112 KB |
Output is correct |
20 |
Correct |
2 ms |
1244 KB |
Output is correct |
21 |
Correct |
2 ms |
1244 KB |
Output is correct |
22 |
Correct |
2 ms |
1244 KB |
Output is correct |
23 |
Correct |
2 ms |
1260 KB |
Output is correct |
24 |
Correct |
2 ms |
1260 KB |
Output is correct |
25 |
Correct |
2 ms |
1260 KB |
Output is correct |
26 |
Correct |
2 ms |
1260 KB |
Output is correct |
27 |
Correct |
3 ms |
1260 KB |
Output is correct |
28 |
Correct |
3 ms |
1260 KB |
Output is correct |
29 |
Correct |
2 ms |
1260 KB |
Output is correct |
30 |
Correct |
2 ms |
1260 KB |
Output is correct |
31 |
Correct |
2 ms |
1260 KB |
Output is correct |
32 |
Correct |
2 ms |
1260 KB |
Output is correct |
33 |
Correct |
2 ms |
1260 KB |
Output is correct |
34 |
Correct |
2 ms |
1260 KB |
Output is correct |
35 |
Correct |
2 ms |
1260 KB |
Output is correct |
36 |
Correct |
3 ms |
1260 KB |
Output is correct |
37 |
Correct |
3 ms |
1260 KB |
Output is correct |
38 |
Correct |
3 ms |
1260 KB |
Output is correct |
39 |
Correct |
3 ms |
1260 KB |
Output is correct |
40 |
Correct |
3 ms |
1260 KB |
Output is correct |
41 |
Correct |
3 ms |
1260 KB |
Output is correct |
42 |
Correct |
3 ms |
1260 KB |
Output is correct |
43 |
Correct |
2 ms |
1260 KB |
Output is correct |
44 |
Correct |
3 ms |
1260 KB |
Output is correct |
45 |
Correct |
3 ms |
1260 KB |
Output is correct |
46 |
Correct |
3 ms |
1260 KB |
Output is correct |
47 |
Correct |
3 ms |
1260 KB |
Output is correct |
48 |
Correct |
3 ms |
1260 KB |
Output is correct |
49 |
Correct |
3 ms |
1260 KB |
Output is correct |
50 |
Correct |
3 ms |
1260 KB |
Output is correct |
51 |
Correct |
3 ms |
1260 KB |
Output is correct |
52 |
Correct |
17 ms |
1380 KB |
Output is correct |
53 |
Correct |
25 ms |
1388 KB |
Output is correct |
54 |
Correct |
45 ms |
1388 KB |
Output is correct |
55 |
Correct |
43 ms |
1388 KB |
Output is correct |
56 |
Correct |
157 ms |
1388 KB |
Output is correct |
57 |
Correct |
158 ms |
1440 KB |
Output is correct |
58 |
Correct |
157 ms |
1440 KB |
Output is correct |
59 |
Correct |
153 ms |
1480 KB |
Output is correct |
60 |
Correct |
165 ms |
1480 KB |
Output is correct |
61 |
Correct |
3 ms |
1480 KB |
Output is correct |
62 |
Correct |
25 ms |
1480 KB |
Output is correct |
63 |
Correct |
48 ms |
1480 KB |
Output is correct |
64 |
Correct |
43 ms |
1480 KB |
Output is correct |
65 |
Correct |
80 ms |
1480 KB |
Output is correct |
66 |
Correct |
118 ms |
1504 KB |
Output is correct |
67 |
Correct |
159 ms |
1528 KB |
Output is correct |
68 |
Correct |
161 ms |
1528 KB |
Output is correct |
69 |
Correct |
155 ms |
1640 KB |
Output is correct |