#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;
template<class A, class B>
bool maximize(A& x, B y) {
if (x < y) return x = y, true; else return false;
}
template<class A, class B>
bool minimize(A& x, B y) {
if (x > y) return x = y, true; else return false;
}
/* END OF TEMPLATE */
const int N = 2e3 + 7;
int n, a[N], A, B;
ll pre[N];
ll getSum(int i, int j) {
return pre[j] - pre[i - 1];
}
namespace sub1 {
const int N = 107;
const int M = 45;
bool f[N][N];
ll solve(int m) {
ll res = 0;
FORD(x, M, 0) {
FOR(i, 0, n)
FOR(j, 0, m + 1) f[i][j] = false;
f[0][0] = true;
REP(i, 0, n)
FOR(j, 0, m)
if (f[i][j]) {
FOR(k, i + 1, n) {
ll sum = getSum(i + 1, k);
if (((res | sum) <= res + MASK(x) - 1)) {
f[k][j + 1] = true;
}
}
}
if (f[n][m]) continue;
res^=MASK(x);
}
return res;
}
void Process() {
ll res = 1e18;
FOR(x, A, B) minimize(res, solve(x));
cout<<res;
}
}
namespace sub2 {
const int N = 2007;
const int M = 45;
int f[N];
ll solve() {
ll res = 0;
FORD(x, M, 0) {
FOR(i, 0, n) f[i] = n + 3;
f[0] = 0;
REP(i, 0, n)
if (f[i] != n + 3) {
FOR(k, i + 1, n) {
ll sum = getSum(i + 1, k);
if (((res | sum) <= res + MASK(x) - 1)) minimize(f[k], f[i] + 1);
}
}
if (f[n] <= B) continue;
res^=MASK(x);
}
return res;
}
void Process() {
cout<<solve();
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>A>>B;
FOR(i, 1, n) {
cin>>a[i];
pre[i] = pre[i - 1] + a[i];
}
if (n <= 100) {
sub1::Process();
return 0;
}
sub2::Process();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
0 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 |
0 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 |
1 ms |
472 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 |
464 KB |
Output is correct |
27 |
Correct |
1 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 |
0 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 |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
464 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 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 |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
5 ms |
348 KB |
Output is correct |
31 |
Correct |
8 ms |
348 KB |
Output is correct |
32 |
Correct |
8 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
8 ms |
344 KB |
Output is correct |
35 |
Correct |
6 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
9 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
344 KB |
Output is correct |
24 |
Correct |
8 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
25 ms |
484 KB |
Output is correct |
27 |
Correct |
142 ms |
468 KB |
Output is correct |
28 |
Correct |
427 ms |
348 KB |
Output is correct |
29 |
Correct |
440 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
143 ms |
460 KB |
Output is correct |
32 |
Correct |
275 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
2 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
456 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
472 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
348 KB |
Output is correct |
41 |
Correct |
8 ms |
348 KB |
Output is correct |
42 |
Correct |
7 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
8 ms |
480 KB |
Output is correct |
45 |
Correct |
6 ms |
348 KB |
Output is correct |
46 |
Correct |
3 ms |
348 KB |
Output is correct |
47 |
Correct |
9 ms |
480 KB |
Output is correct |
48 |
Correct |
4 ms |
488 KB |
Output is correct |
49 |
Correct |
24 ms |
348 KB |
Output is correct |
50 |
Correct |
149 ms |
708 KB |
Output is correct |
51 |
Correct |
458 ms |
344 KB |
Output is correct |
52 |
Correct |
443 ms |
592 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
149 ms |
348 KB |
Output is correct |
55 |
Correct |
290 ms |
456 KB |
Output is correct |
56 |
Correct |
4 ms |
476 KB |
Output is correct |
57 |
Correct |
12 ms |
488 KB |
Output is correct |
58 |
Correct |
64 ms |
348 KB |
Output is correct |
59 |
Correct |
181 ms |
460 KB |
Output is correct |
60 |
Correct |
222 ms |
476 KB |
Output is correct |
61 |
Correct |
0 ms |
344 KB |
Output is correct |
62 |
Correct |
234 ms |
348 KB |
Output is correct |
63 |
Correct |
273 ms |
460 KB |
Output is correct |
64 |
Correct |
190 ms |
476 KB |
Output is correct |
65 |
Correct |
3 ms |
348 KB |
Output is correct |
66 |
Correct |
3 ms |
348 KB |
Output is correct |
67 |
Correct |
13 ms |
348 KB |
Output is correct |
68 |
Correct |
53 ms |
456 KB |
Output is correct |
69 |
Correct |
101 ms |
456 KB |
Output is correct |
70 |
Correct |
132 ms |
460 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
220 ms |
472 KB |
Output is correct |
73 |
Correct |
76 ms |
348 KB |
Output is correct |
74 |
Correct |
87 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
7 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
348 KB |
Output is correct |
29 |
Correct |
8 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
8 ms |
480 KB |
Output is correct |
32 |
Correct |
6 ms |
344 KB |
Output is correct |
33 |
Correct |
3 ms |
344 KB |
Output is correct |
34 |
Correct |
8 ms |
348 KB |
Output is correct |
35 |
Correct |
5 ms |
344 KB |
Output is correct |
36 |
Correct |
23 ms |
344 KB |
Output is correct |
37 |
Correct |
147 ms |
456 KB |
Output is correct |
38 |
Correct |
460 ms |
348 KB |
Output is correct |
39 |
Correct |
443 ms |
464 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
138 ms |
348 KB |
Output is correct |
42 |
Correct |
290 ms |
460 KB |
Output is correct |
43 |
Correct |
4 ms |
348 KB |
Output is correct |
44 |
Correct |
12 ms |
348 KB |
Output is correct |
45 |
Correct |
66 ms |
460 KB |
Output is correct |
46 |
Correct |
186 ms |
344 KB |
Output is correct |
47 |
Correct |
224 ms |
460 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
231 ms |
464 KB |
Output is correct |
50 |
Correct |
273 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
344 KB |
Output is correct |
52 |
Correct |
6 ms |
460 KB |
Output is correct |
53 |
Correct |
4 ms |
348 KB |
Output is correct |
54 |
Correct |
17 ms |
344 KB |
Output is correct |
55 |
Correct |
12 ms |
344 KB |
Output is correct |
56 |
Correct |
26 ms |
348 KB |
Output is correct |
57 |
Correct |
25 ms |
344 KB |
Output is correct |
58 |
Correct |
34 ms |
512 KB |
Output is correct |
59 |
Correct |
53 ms |
496 KB |
Output is correct |
60 |
Correct |
32 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
4 ms |
604 KB |
Output is correct |
63 |
Correct |
31 ms |
348 KB |
Output is correct |
64 |
Correct |
6 ms |
348 KB |
Output is correct |
65 |
Correct |
12 ms |
500 KB |
Output is correct |
66 |
Correct |
18 ms |
348 KB |
Output is correct |
67 |
Correct |
24 ms |
520 KB |
Output is correct |
68 |
Correct |
66 ms |
344 KB |
Output is correct |
69 |
Correct |
30 ms |
348 KB |
Output is correct |