#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a); i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"debug"<<endl
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
vector<ll> arr;
vector<ll> psum;
int dp[2002][2002];
int n, a, b;
ll currbest = 0;
bool solve(ll bit) {
ll mx = currbest+(1LL<<bit);
if(a==1) {
owo(i, 0, n+1) {
dp[0][i] = INF;
}
dp[0][0] = 0;
owo(i, 0, n) {
owo(j, 0, i+1) {
//cout<<currbest<<" "<<(psum[i+1]-psum[j])<<" "<<(currbest|(psum[i+1]-psum[j]))<<" "<<mx<<"\n";
if((currbest|(psum[i+1]-psum[j]))<mx) {
dp[0][i+1] = min(dp[0][i+1] , dp[0][j] + 1);
}
}
}
return dp[0][n]>b;
}else {
owo(i, 0, 2002) {
owo(j, 0, 2002) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
owo(i, 0, n) {
owo(j, 0, i+1) {
if((currbest|(psum[i+1]-psum[j]))<mx) {
owo(k, 0, b) {
if(dp[j][k]) {
dp[i+1][k+1] = 1;
}
}
}
}
}
for(int i=a; i<=b; ++i) {
if(dp[n][i]) {
return false;
}
}
return true;
}
}
int main()
{
//freopen("filename.in", "r", stdin);
//freopen("filename.out", "w", stdout);
cin.tie(0)->sync_with_stdio(0);
cin>>n>>a>>b;
arr.resize(n);
psum.resize(n+1);
psum[0] = 0;
owo(i, 0, n) {
cin>>arr[i];
psum[i+1] = psum[i] + arr[i];
}
for(ll i = 40; i>=0; --i) {
if(solve(i)) {
currbest+=(1LL<<i);
}
}
cout<<currbest<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
101 ms |
16000 KB |
Output is correct |
15 |
Correct |
100 ms |
16000 KB |
Output is correct |
16 |
Correct |
94 ms |
16000 KB |
Output is correct |
17 |
Correct |
94 ms |
16000 KB |
Output is correct |
18 |
Correct |
98 ms |
16000 KB |
Output is correct |
19 |
Correct |
133 ms |
16120 KB |
Output is correct |
20 |
Correct |
107 ms |
16120 KB |
Output is correct |
21 |
Correct |
109 ms |
16000 KB |
Output is correct |
22 |
Correct |
110 ms |
16000 KB |
Output is correct |
23 |
Correct |
113 ms |
16048 KB |
Output is correct |
24 |
Correct |
100 ms |
16000 KB |
Output is correct |
25 |
Correct |
101 ms |
16000 KB |
Output is correct |
26 |
Correct |
111 ms |
16000 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
101 ms |
16120 KB |
Output is correct |
15 |
Correct |
101 ms |
16000 KB |
Output is correct |
16 |
Correct |
112 ms |
16000 KB |
Output is correct |
17 |
Correct |
97 ms |
16000 KB |
Output is correct |
18 |
Correct |
97 ms |
16000 KB |
Output is correct |
19 |
Correct |
101 ms |
16068 KB |
Output is correct |
20 |
Correct |
96 ms |
16000 KB |
Output is correct |
21 |
Correct |
107 ms |
16000 KB |
Output is correct |
22 |
Correct |
106 ms |
16120 KB |
Output is correct |
23 |
Correct |
98 ms |
16000 KB |
Output is correct |
24 |
Correct |
95 ms |
16000 KB |
Output is correct |
25 |
Correct |
96 ms |
16100 KB |
Output is correct |
26 |
Correct |
112 ms |
16000 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
110 ms |
16000 KB |
Output is correct |
15 |
Correct |
98 ms |
16000 KB |
Output is correct |
16 |
Correct |
100 ms |
16000 KB |
Output is correct |
17 |
Correct |
112 ms |
16000 KB |
Output is correct |
18 |
Correct |
112 ms |
16120 KB |
Output is correct |
19 |
Correct |
94 ms |
16000 KB |
Output is correct |
20 |
Correct |
94 ms |
16000 KB |
Output is correct |
21 |
Correct |
93 ms |
16000 KB |
Output is correct |
22 |
Correct |
96 ms |
16000 KB |
Output is correct |
23 |
Correct |
99 ms |
16000 KB |
Output is correct |
24 |
Correct |
98 ms |
16000 KB |
Output is correct |
25 |
Correct |
95 ms |
16000 KB |
Output is correct |
26 |
Correct |
104 ms |
16000 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
384 KB |
Output is correct |
38 |
Correct |
4 ms |
384 KB |
Output is correct |
39 |
Correct |
5 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
384 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
5 ms |
384 KB |
Output is correct |
54 |
Correct |
5 ms |
384 KB |
Output is correct |
55 |
Correct |
5 ms |
384 KB |
Output is correct |
56 |
Correct |
5 ms |
384 KB |
Output is correct |
57 |
Correct |
5 ms |
384 KB |
Output is correct |
58 |
Correct |
5 ms |
384 KB |
Output is correct |
59 |
Correct |
5 ms |
384 KB |
Output is correct |
60 |
Correct |
5 ms |
384 KB |
Output is correct |
61 |
Correct |
5 ms |
384 KB |
Output is correct |
62 |
Correct |
5 ms |
384 KB |
Output is correct |
63 |
Correct |
5 ms |
384 KB |
Output is correct |
64 |
Correct |
114 ms |
16000 KB |
Output is correct |
65 |
Correct |
107 ms |
16000 KB |
Output is correct |
66 |
Correct |
95 ms |
16000 KB |
Output is correct |
67 |
Correct |
97 ms |
16000 KB |
Output is correct |
68 |
Correct |
99 ms |
16120 KB |
Output is correct |
69 |
Correct |
112 ms |
16000 KB |
Output is correct |
70 |
Correct |
108 ms |
16120 KB |
Output is correct |
71 |
Correct |
100 ms |
16120 KB |
Output is correct |
72 |
Correct |
105 ms |
16000 KB |
Output is correct |
73 |
Correct |
113 ms |
16000 KB |
Output is correct |
74 |
Correct |
98 ms |
16000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
5 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
384 KB |
Output is correct |
52 |
Correct |
14 ms |
384 KB |
Output is correct |
53 |
Correct |
19 ms |
384 KB |
Output is correct |
54 |
Correct |
30 ms |
384 KB |
Output is correct |
55 |
Correct |
28 ms |
384 KB |
Output is correct |
56 |
Correct |
91 ms |
384 KB |
Output is correct |
57 |
Correct |
94 ms |
384 KB |
Output is correct |
58 |
Correct |
84 ms |
384 KB |
Output is correct |
59 |
Correct |
90 ms |
384 KB |
Output is correct |
60 |
Correct |
101 ms |
384 KB |
Output is correct |
61 |
Correct |
5 ms |
384 KB |
Output is correct |
62 |
Correct |
18 ms |
384 KB |
Output is correct |
63 |
Correct |
31 ms |
384 KB |
Output is correct |
64 |
Correct |
27 ms |
384 KB |
Output is correct |
65 |
Correct |
54 ms |
384 KB |
Output is correct |
66 |
Correct |
72 ms |
384 KB |
Output is correct |
67 |
Correct |
90 ms |
384 KB |
Output is correct |
68 |
Correct |
95 ms |
384 KB |
Output is correct |
69 |
Correct |
88 ms |
384 KB |
Output is correct |