#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
360 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 |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 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 |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 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 |
428 KB |
Output is correct |
36 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 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 |
344 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 |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
600 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 |
10 ms |
348 KB |
Output is correct |
32 |
Correct |
9 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
360 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
0 ms |
360 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
8 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
8 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
348 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 |
348 KB |
Output is correct |
27 |
Correct |
137 ms |
344 KB |
Output is correct |
28 |
Correct |
447 ms |
708 KB |
Output is correct |
29 |
Correct |
431 ms |
456 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
141 ms |
456 KB |
Output is correct |
32 |
Correct |
283 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 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 |
1 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 |
348 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 |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 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 |
472 KB |
Output is correct |
37 |
Correct |
2 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
388 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
348 KB |
Output is correct |
41 |
Correct |
9 ms |
348 KB |
Output is correct |
42 |
Correct |
8 ms |
472 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
9 ms |
348 KB |
Output is correct |
45 |
Correct |
6 ms |
348 KB |
Output is correct |
46 |
Correct |
3 ms |
348 KB |
Output is correct |
47 |
Correct |
8 ms |
344 KB |
Output is correct |
48 |
Correct |
4 ms |
348 KB |
Output is correct |
49 |
Correct |
26 ms |
480 KB |
Output is correct |
50 |
Correct |
142 ms |
348 KB |
Output is correct |
51 |
Correct |
432 ms |
348 KB |
Output is correct |
52 |
Correct |
437 ms |
456 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
142 ms |
452 KB |
Output is correct |
55 |
Correct |
294 ms |
452 KB |
Output is correct |
56 |
Correct |
4 ms |
344 KB |
Output is correct |
57 |
Correct |
16 ms |
348 KB |
Output is correct |
58 |
Correct |
67 ms |
456 KB |
Output is correct |
59 |
Correct |
177 ms |
460 KB |
Output is correct |
60 |
Correct |
238 ms |
456 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
234 ms |
456 KB |
Output is correct |
63 |
Correct |
269 ms |
456 KB |
Output is correct |
64 |
Correct |
183 ms |
348 KB |
Output is correct |
65 |
Correct |
3 ms |
348 KB |
Output is correct |
66 |
Correct |
3 ms |
348 KB |
Output is correct |
67 |
Correct |
12 ms |
600 KB |
Output is correct |
68 |
Correct |
53 ms |
348 KB |
Output is correct |
69 |
Correct |
97 ms |
452 KB |
Output is correct |
70 |
Correct |
134 ms |
460 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
224 ms |
348 KB |
Output is correct |
73 |
Correct |
76 ms |
344 KB |
Output is correct |
74 |
Correct |
87 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
392 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
472 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
5 ms |
348 KB |
Output is correct |
28 |
Correct |
8 ms |
348 KB |
Output is correct |
29 |
Correct |
9 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
8 ms |
476 KB |
Output is correct |
32 |
Correct |
6 ms |
348 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
8 ms |
348 KB |
Output is correct |
35 |
Correct |
5 ms |
348 KB |
Output is correct |
36 |
Correct |
24 ms |
348 KB |
Output is correct |
37 |
Correct |
140 ms |
456 KB |
Output is correct |
38 |
Correct |
436 ms |
456 KB |
Output is correct |
39 |
Correct |
479 ms |
456 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
137 ms |
344 KB |
Output is correct |
42 |
Correct |
288 ms |
348 KB |
Output is correct |
43 |
Correct |
4 ms |
348 KB |
Output is correct |
44 |
Correct |
14 ms |
628 KB |
Output is correct |
45 |
Correct |
62 ms |
348 KB |
Output is correct |
46 |
Correct |
194 ms |
460 KB |
Output is correct |
47 |
Correct |
217 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
228 ms |
456 KB |
Output is correct |
50 |
Correct |
284 ms |
456 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
4 ms |
348 KB |
Output is correct |
53 |
Correct |
4 ms |
348 KB |
Output is correct |
54 |
Correct |
17 ms |
500 KB |
Output is correct |
55 |
Correct |
12 ms |
348 KB |
Output is correct |
56 |
Correct |
28 ms |
504 KB |
Output is correct |
57 |
Correct |
23 ms |
348 KB |
Output is correct |
58 |
Correct |
31 ms |
348 KB |
Output is correct |
59 |
Correct |
51 ms |
492 KB |
Output is correct |
60 |
Correct |
31 ms |
344 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
4 ms |
348 KB |
Output is correct |
63 |
Correct |
18 ms |
348 KB |
Output is correct |
64 |
Correct |
6 ms |
348 KB |
Output is correct |
65 |
Correct |
17 ms |
500 KB |
Output is correct |
66 |
Correct |
17 ms |
348 KB |
Output is correct |
67 |
Correct |
23 ms |
344 KB |
Output is correct |
68 |
Correct |
73 ms |
492 KB |
Output is correct |
69 |
Correct |
23 ms |
348 KB |
Output is correct |