//#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
typedef pair<int,int> pii;
const int maxn = 1e2+5;
int arr[2005], ans = 0, n, A, B;
int pre[2005];
int two[60];
const int INF = 1e18;
void solve() {
int dp[maxn][maxn];
int digit = __lg(pre[n]);
for(int x=digit; x>=0; x--) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i=1; i<=n; i++) {
for(int j=1; j<=i; j++) {
for(int k=0; k<i; k++) {
if(dp[k][j-1]) {
int tmp = pre[i] - pre[k];
if((tmp & (two[x])) == 0 &&((tmp>>(int)(x+1))|ans)==ans ) {
dp[i][j] = 1;
}
}
}
}
}
ans<<=1;
ans++;
for(int i=A; i<=B; i++) {
if(dp[n][i]) {
ans--;
break;
}
}
}
}
void solve2() {
int dp[2005];
dp[0] = 0;
int digit = __lg(pre[n]);
for(int x=digit; x>=0; x--) {
for(int i=1; i<=n; i++) {
dp[i] = INF;
}
dp[0] = 0;
for(int i=1; i<=n; i++) {
for(int j=0; j<i; j++) {
if(dp[j] < B) {
int tmp = pre[i] - pre[j];
if((tmp & (two[x])) == 0 &&((tmp>>(int)(x+1))|ans)==ans) {
dp[i] = min(dp[i], dp[j]+1);
}
}
}
}
ans <<= 1;
ans++;
if(dp[n] <= B)ans--;
}
}
main() {
// int n, A, B;
cin >> n >> A >> B;
two[0] = 1;
for(int i=1; i<60; i++) {
two[i] = two[i-1] * 2;
}
pre[0] = 0;
for(int i=1; i<=n; i++) {
cin >> arr[i];
pre[i] = pre[i-1] + arr[i];
}
if(n>100)solve2();
else
solve();
cout << ans << "\n";
}
Compilation message
sculpture.cpp:70:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
380 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
380 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
408 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
6 ms |
376 KB |
Output is correct |
34 |
Correct |
6 ms |
376 KB |
Output is correct |
35 |
Correct |
6 ms |
376 KB |
Output is correct |
36 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
380 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
7 ms |
376 KB |
Output is correct |
26 |
Correct |
8 ms |
376 KB |
Output is correct |
27 |
Correct |
9 ms |
376 KB |
Output is correct |
28 |
Correct |
10 ms |
376 KB |
Output is correct |
29 |
Correct |
11 ms |
504 KB |
Output is correct |
30 |
Correct |
11 ms |
376 KB |
Output is correct |
31 |
Correct |
11 ms |
376 KB |
Output is correct |
32 |
Correct |
10 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
408 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
380 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
6 ms |
504 KB |
Output is correct |
40 |
Correct |
6 ms |
380 KB |
Output is correct |
41 |
Correct |
6 ms |
376 KB |
Output is correct |
42 |
Correct |
6 ms |
376 KB |
Output is correct |
43 |
Correct |
6 ms |
376 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
46 |
Correct |
6 ms |
376 KB |
Output is correct |
47 |
Correct |
6 ms |
376 KB |
Output is correct |
48 |
Correct |
7 ms |
376 KB |
Output is correct |
49 |
Correct |
8 ms |
376 KB |
Output is correct |
50 |
Correct |
9 ms |
376 KB |
Output is correct |
51 |
Correct |
11 ms |
376 KB |
Output is correct |
52 |
Correct |
11 ms |
376 KB |
Output is correct |
53 |
Correct |
11 ms |
376 KB |
Output is correct |
54 |
Correct |
11 ms |
376 KB |
Output is correct |
55 |
Correct |
14 ms |
428 KB |
Output is correct |
56 |
Correct |
8 ms |
380 KB |
Output is correct |
57 |
Correct |
15 ms |
380 KB |
Output is correct |
58 |
Correct |
17 ms |
376 KB |
Output is correct |
59 |
Correct |
21 ms |
376 KB |
Output is correct |
60 |
Correct |
22 ms |
376 KB |
Output is correct |
61 |
Correct |
21 ms |
376 KB |
Output is correct |
62 |
Correct |
21 ms |
376 KB |
Output is correct |
63 |
Correct |
22 ms |
376 KB |
Output is correct |
64 |
Correct |
8 ms |
376 KB |
Output is correct |
65 |
Correct |
8 ms |
376 KB |
Output is correct |
66 |
Correct |
11 ms |
376 KB |
Output is correct |
67 |
Correct |
13 ms |
376 KB |
Output is correct |
68 |
Correct |
20 ms |
376 KB |
Output is correct |
69 |
Correct |
20 ms |
376 KB |
Output is correct |
70 |
Correct |
25 ms |
376 KB |
Output is correct |
71 |
Correct |
22 ms |
376 KB |
Output is correct |
72 |
Correct |
20 ms |
376 KB |
Output is correct |
73 |
Correct |
20 ms |
376 KB |
Output is correct |
74 |
Correct |
20 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
8 ms |
380 KB |
Output is correct |
32 |
Correct |
7 ms |
380 KB |
Output is correct |
33 |
Correct |
6 ms |
376 KB |
Output is correct |
34 |
Correct |
6 ms |
376 KB |
Output is correct |
35 |
Correct |
7 ms |
376 KB |
Output is correct |
36 |
Correct |
8 ms |
376 KB |
Output is correct |
37 |
Correct |
9 ms |
376 KB |
Output is correct |
38 |
Correct |
10 ms |
376 KB |
Output is correct |
39 |
Correct |
11 ms |
376 KB |
Output is correct |
40 |
Correct |
12 ms |
376 KB |
Output is correct |
41 |
Correct |
11 ms |
376 KB |
Output is correct |
42 |
Correct |
11 ms |
380 KB |
Output is correct |
43 |
Correct |
7 ms |
376 KB |
Output is correct |
44 |
Correct |
14 ms |
376 KB |
Output is correct |
45 |
Correct |
18 ms |
376 KB |
Output is correct |
46 |
Correct |
21 ms |
376 KB |
Output is correct |
47 |
Correct |
21 ms |
376 KB |
Output is correct |
48 |
Correct |
20 ms |
376 KB |
Output is correct |
49 |
Correct |
20 ms |
376 KB |
Output is correct |
50 |
Correct |
21 ms |
376 KB |
Output is correct |
51 |
Correct |
5 ms |
376 KB |
Output is correct |
52 |
Correct |
30 ms |
376 KB |
Output is correct |
53 |
Correct |
20 ms |
376 KB |
Output is correct |
54 |
Correct |
107 ms |
504 KB |
Output is correct |
55 |
Correct |
79 ms |
376 KB |
Output is correct |
56 |
Correct |
124 ms |
376 KB |
Output is correct |
57 |
Correct |
110 ms |
376 KB |
Output is correct |
58 |
Correct |
130 ms |
504 KB |
Output is correct |
59 |
Correct |
127 ms |
376 KB |
Output is correct |
60 |
Correct |
80 ms |
376 KB |
Output is correct |
61 |
Correct |
6 ms |
376 KB |
Output is correct |
62 |
Correct |
22 ms |
380 KB |
Output is correct |
63 |
Correct |
110 ms |
376 KB |
Output is correct |
64 |
Correct |
33 ms |
376 KB |
Output is correct |
65 |
Correct |
59 ms |
376 KB |
Output is correct |
66 |
Correct |
86 ms |
632 KB |
Output is correct |
67 |
Correct |
77 ms |
504 KB |
Output is correct |
68 |
Correct |
349 ms |
480 KB |
Output is correct |
69 |
Correct |
117 ms |
504 KB |
Output is correct |