#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
/*typedef __uint128_t L;
struct FastMod {
ull b, m;
FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
ull reduce(ull a) {
ull q = (ull)((L(m) * a) >> 64);
ull r = a - q * b; // can be proven that 0 <= r < 2*b
return r >= b ? r - b : r;
}
};
FastMod FM(2);*/
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e3 + 10;
const int lg = 42;
const int inf = 1e9;
int n, A, B, a[maxn], dp[maxn][maxn];
ll part[maxn];
set<int> opt[maxn];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) part[i] = part[i-1] + a[i];
for (int i = 1; i <= n; i++){
for (int j = 0; j < i; j++){
opt[i].insert(j);
}
}
if (A == 1){
ll ans = 0;
for (int k = lg - 1; ~k; k--){
for (int i = 1; i <= n; i++){
dp[0][i] = inf;
for (auto x: opt[i]){
ll tmp = part[i] - part[x];
if ((tmp >> k) & 1) continue;
dp[0][i] = min(dp[0][i], dp[0][x] + 1);
}
}
if (dp[0][n] <= B){
for (int i = 1; i <= n; i++){
vector<int> del;
for (auto x: opt[i]){
ll tmp = part[i] - part[x];
if ((tmp >> k) & 1) del.push_back(x);
}
for (auto x: del){
opt[i].erase(x);
}
}
}
else{
ans += (1ll << k);
}
}
cout << ans << '\n';
return 0;
}
ll ans = 0;
for (int k = lg - 1; ~k; k--){
dp[0][0] = 1;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
dp[i][j] = 0;
for (auto x: opt[j]){
ll tmp = part[j] - part[x];
if ((tmp >> k) & 1) continue;
dp[i][j] = max(dp[i][j], dp[i-1][x]);
}
}
}
bool flg = false;
for (int i = A; i <= B; i++){
if (dp[i][n]) flg = true;
}
if (flg){
for (int i = 1; i <= n; i++){
vector<int> del;
for (auto x: opt[i]){
ll tmp = part[i] - part[x];
if ((tmp >> k) & 1) del.push_back(x);
}
for (auto x: del){
opt[i].erase(x);
}
}
}
else{
ans += (1ll << k);
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
420 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
424 KB |
Output is correct |
10 |
Correct |
1 ms |
420 KB |
Output is correct |
11 |
Correct |
1 ms |
416 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 |
420 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
424 KB |
Output is correct |
20 |
Correct |
1 ms |
420 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 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 |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 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 |
416 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
416 KB |
Output is correct |
2 |
Correct |
1 ms |
424 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 |
420 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
420 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 |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
416 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
424 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
420 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 |
420 KB |
Output is correct |
33 |
Correct |
1 ms |
468 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 |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
340 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 |
1 ms |
416 KB |
Output is correct |
12 |
Correct |
1 ms |
416 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
416 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 |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
548 KB |
Output is correct |
27 |
Correct |
3 ms |
596 KB |
Output is correct |
28 |
Correct |
3 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
4 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
548 KB |
Output is correct |
32 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
416 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
420 KB |
Output is correct |
4 |
Correct |
1 ms |
424 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
352 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 |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
428 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
416 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
416 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
424 KB |
Output is correct |
27 |
Correct |
0 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 |
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 |
420 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
424 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
416 KB |
Output is correct |
39 |
Correct |
1 ms |
416 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
420 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 |
420 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
420 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
2 ms |
468 KB |
Output is correct |
49 |
Correct |
2 ms |
468 KB |
Output is correct |
50 |
Correct |
2 ms |
596 KB |
Output is correct |
51 |
Correct |
3 ms |
548 KB |
Output is correct |
52 |
Correct |
3 ms |
548 KB |
Output is correct |
53 |
Correct |
3 ms |
544 KB |
Output is correct |
54 |
Correct |
3 ms |
596 KB |
Output is correct |
55 |
Correct |
3 ms |
596 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
548 KB |
Output is correct |
58 |
Correct |
2 ms |
596 KB |
Output is correct |
59 |
Correct |
2 ms |
544 KB |
Output is correct |
60 |
Correct |
2 ms |
544 KB |
Output is correct |
61 |
Correct |
2 ms |
596 KB |
Output is correct |
62 |
Correct |
2 ms |
548 KB |
Output is correct |
63 |
Correct |
2 ms |
668 KB |
Output is correct |
64 |
Correct |
70 ms |
980 KB |
Output is correct |
65 |
Correct |
5 ms |
596 KB |
Output is correct |
66 |
Correct |
11 ms |
812 KB |
Output is correct |
67 |
Correct |
14 ms |
916 KB |
Output is correct |
68 |
Correct |
23 ms |
940 KB |
Output is correct |
69 |
Correct |
27 ms |
1060 KB |
Output is correct |
70 |
Correct |
22 ms |
980 KB |
Output is correct |
71 |
Correct |
29 ms |
980 KB |
Output is correct |
72 |
Correct |
40 ms |
980 KB |
Output is correct |
73 |
Correct |
38 ms |
1108 KB |
Output is correct |
74 |
Correct |
39 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
424 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
420 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 |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
416 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
416 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
424 KB |
Output is correct |
30 |
Correct |
2 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 |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
416 KB |
Output is correct |
35 |
Correct |
2 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
644 KB |
Output is correct |
39 |
Correct |
3 ms |
548 KB |
Output is correct |
40 |
Correct |
3 ms |
596 KB |
Output is correct |
41 |
Correct |
3 ms |
596 KB |
Output is correct |
42 |
Correct |
3 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
544 KB |
Output is correct |
45 |
Correct |
2 ms |
596 KB |
Output is correct |
46 |
Correct |
2 ms |
596 KB |
Output is correct |
47 |
Correct |
2 ms |
596 KB |
Output is correct |
48 |
Correct |
2 ms |
596 KB |
Output is correct |
49 |
Correct |
3 ms |
548 KB |
Output is correct |
50 |
Correct |
2 ms |
596 KB |
Output is correct |
51 |
Correct |
2 ms |
596 KB |
Output is correct |
52 |
Correct |
40 ms |
8148 KB |
Output is correct |
53 |
Correct |
72 ms |
13560 KB |
Output is correct |
54 |
Correct |
136 ms |
23896 KB |
Output is correct |
55 |
Correct |
139 ms |
23940 KB |
Output is correct |
56 |
Correct |
512 ms |
94432 KB |
Output is correct |
57 |
Correct |
518 ms |
94500 KB |
Output is correct |
58 |
Correct |
480 ms |
94432 KB |
Output is correct |
59 |
Correct |
473 ms |
94412 KB |
Output is correct |
60 |
Correct |
646 ms |
94440 KB |
Output is correct |
61 |
Correct |
2 ms |
596 KB |
Output is correct |
62 |
Correct |
72 ms |
13552 KB |
Output is correct |
63 |
Correct |
137 ms |
23840 KB |
Output is correct |
64 |
Correct |
140 ms |
24116 KB |
Output is correct |
65 |
Correct |
254 ms |
46728 KB |
Output is correct |
66 |
Correct |
375 ms |
72152 KB |
Output is correct |
67 |
Correct |
515 ms |
94320 KB |
Output is correct |
68 |
Correct |
517 ms |
94432 KB |
Output is correct |
69 |
Correct |
473 ms |
94432 KB |
Output is correct |