#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define name "main"
const int maxlog=(int)40;
const int N=(int)2000;
ll arr[N+2]={};
ll ans=((ll)1<<maxlog)-1;
ll dp[N+2][N+2]={};
int n,a,b;
bool possible(ll limit){
memset(dp,0x3f,sizeof dp);
int INF=dp[0][0];
dp[0][0]=0;
for (int i=1;i<=n;++i){
ll tot=0;
for (int j=i;j<=n;++j){
tot+=arr[j];
if ((tot&limit)!=tot) continue;
if (a==1) dp[j][1]=min(min(dp[i-1][0],dp[i-1][1])+1,dp[j][1]);
else{
for (int block=1;block<=min(i,b);++block){
dp[j][block]=min(dp[i-1][block-1]+1,dp[j][block]);
}
}
}
}
if (a==1){
if (dp[n][1]<=b) return true;
return false;
}
for (int i=a;i<=b;++i)
if (dp[n][i]!=i) return false;
return true;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>a>>b;
for (int i=1;i<=n;++i) cin>>arr[i];
for (int i=maxlog-1;i>=0;--i){
if (possible(ans^((ll)1<<i))) {
ans^=((ll)1<<i);
}
}
cout<<ans;
exit(0);
}
Compilation message
sculpture.cpp: In function 'bool possible(ll)':
sculpture.cpp:16:6: warning: unused variable 'INF' [-Wunused-variable]
16 | int INF=dp[0][0];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
31824 KB |
Output is correct |
2 |
Correct |
46 ms |
31824 KB |
Output is correct |
3 |
Correct |
44 ms |
31824 KB |
Output is correct |
4 |
Correct |
45 ms |
31824 KB |
Output is correct |
5 |
Correct |
45 ms |
31824 KB |
Output is correct |
6 |
Correct |
50 ms |
31824 KB |
Output is correct |
7 |
Correct |
57 ms |
31824 KB |
Output is correct |
8 |
Correct |
37 ms |
31824 KB |
Output is correct |
9 |
Correct |
37 ms |
31824 KB |
Output is correct |
10 |
Correct |
32 ms |
31808 KB |
Output is correct |
11 |
Correct |
45 ms |
31824 KB |
Output is correct |
12 |
Correct |
44 ms |
31824 KB |
Output is correct |
13 |
Correct |
52 ms |
31824 KB |
Output is correct |
14 |
Incorrect |
46 ms |
31824 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
31824 KB |
Output is correct |
2 |
Correct |
45 ms |
31824 KB |
Output is correct |
3 |
Correct |
47 ms |
31824 KB |
Output is correct |
4 |
Correct |
46 ms |
31824 KB |
Output is correct |
5 |
Correct |
43 ms |
31808 KB |
Output is correct |
6 |
Correct |
46 ms |
31824 KB |
Output is correct |
7 |
Correct |
44 ms |
31824 KB |
Output is correct |
8 |
Correct |
50 ms |
32076 KB |
Output is correct |
9 |
Correct |
51 ms |
31824 KB |
Output is correct |
10 |
Correct |
47 ms |
31824 KB |
Output is correct |
11 |
Correct |
41 ms |
31824 KB |
Output is correct |
12 |
Correct |
45 ms |
31992 KB |
Output is correct |
13 |
Correct |
43 ms |
31824 KB |
Output is correct |
14 |
Incorrect |
39 ms |
31824 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
31836 KB |
Output is correct |
2 |
Correct |
41 ms |
31824 KB |
Output is correct |
3 |
Correct |
51 ms |
31824 KB |
Output is correct |
4 |
Correct |
45 ms |
31824 KB |
Output is correct |
5 |
Correct |
41 ms |
31824 KB |
Output is correct |
6 |
Correct |
44 ms |
31824 KB |
Output is correct |
7 |
Correct |
42 ms |
31824 KB |
Output is correct |
8 |
Correct |
39 ms |
31824 KB |
Output is correct |
9 |
Correct |
40 ms |
31824 KB |
Output is correct |
10 |
Correct |
38 ms |
31824 KB |
Output is correct |
11 |
Correct |
42 ms |
31824 KB |
Output is correct |
12 |
Correct |
47 ms |
31824 KB |
Output is correct |
13 |
Correct |
44 ms |
31824 KB |
Output is correct |
14 |
Correct |
43 ms |
31824 KB |
Output is correct |
15 |
Correct |
40 ms |
31824 KB |
Output is correct |
16 |
Correct |
42 ms |
31824 KB |
Output is correct |
17 |
Correct |
39 ms |
31824 KB |
Output is correct |
18 |
Correct |
36 ms |
31824 KB |
Output is correct |
19 |
Correct |
50 ms |
31824 KB |
Output is correct |
20 |
Correct |
43 ms |
31824 KB |
Output is correct |
21 |
Correct |
42 ms |
31996 KB |
Output is correct |
22 |
Correct |
38 ms |
31992 KB |
Output is correct |
23 |
Correct |
36 ms |
31812 KB |
Output is correct |
24 |
Correct |
37 ms |
31824 KB |
Output is correct |
25 |
Correct |
45 ms |
31996 KB |
Output is correct |
26 |
Correct |
43 ms |
31824 KB |
Output is correct |
27 |
Correct |
42 ms |
31824 KB |
Output is correct |
28 |
Correct |
45 ms |
31824 KB |
Output is correct |
29 |
Correct |
44 ms |
31996 KB |
Output is correct |
30 |
Correct |
43 ms |
31824 KB |
Output is correct |
31 |
Correct |
45 ms |
31840 KB |
Output is correct |
32 |
Correct |
42 ms |
31992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
31824 KB |
Output is correct |
2 |
Correct |
41 ms |
31824 KB |
Output is correct |
3 |
Correct |
43 ms |
31824 KB |
Output is correct |
4 |
Correct |
45 ms |
31824 KB |
Output is correct |
5 |
Correct |
44 ms |
31824 KB |
Output is correct |
6 |
Correct |
42 ms |
31824 KB |
Output is correct |
7 |
Correct |
44 ms |
31824 KB |
Output is correct |
8 |
Correct |
42 ms |
31992 KB |
Output is correct |
9 |
Correct |
45 ms |
31824 KB |
Output is correct |
10 |
Correct |
48 ms |
31824 KB |
Output is correct |
11 |
Correct |
49 ms |
31824 KB |
Output is correct |
12 |
Correct |
54 ms |
31824 KB |
Output is correct |
13 |
Correct |
46 ms |
31824 KB |
Output is correct |
14 |
Incorrect |
42 ms |
31824 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
31836 KB |
Output is correct |
2 |
Correct |
46 ms |
31824 KB |
Output is correct |
3 |
Correct |
47 ms |
31824 KB |
Output is correct |
4 |
Correct |
49 ms |
31824 KB |
Output is correct |
5 |
Correct |
55 ms |
31824 KB |
Output is correct |
6 |
Correct |
48 ms |
31824 KB |
Output is correct |
7 |
Correct |
48 ms |
31992 KB |
Output is correct |
8 |
Correct |
49 ms |
31824 KB |
Output is correct |
9 |
Correct |
49 ms |
31824 KB |
Output is correct |
10 |
Correct |
47 ms |
31824 KB |
Output is correct |
11 |
Correct |
49 ms |
31824 KB |
Output is correct |
12 |
Correct |
51 ms |
31824 KB |
Output is correct |
13 |
Correct |
52 ms |
31824 KB |
Output is correct |
14 |
Correct |
48 ms |
31824 KB |
Output is correct |
15 |
Correct |
48 ms |
31824 KB |
Output is correct |
16 |
Correct |
46 ms |
31824 KB |
Output is correct |
17 |
Correct |
50 ms |
31824 KB |
Output is correct |
18 |
Correct |
46 ms |
31824 KB |
Output is correct |
19 |
Correct |
45 ms |
31844 KB |
Output is correct |
20 |
Correct |
50 ms |
31824 KB |
Output is correct |
21 |
Correct |
47 ms |
31824 KB |
Output is correct |
22 |
Correct |
44 ms |
31824 KB |
Output is correct |
23 |
Correct |
39 ms |
31824 KB |
Output is correct |
24 |
Correct |
46 ms |
31824 KB |
Output is correct |
25 |
Correct |
44 ms |
31824 KB |
Output is correct |
26 |
Correct |
46 ms |
31824 KB |
Output is correct |
27 |
Correct |
45 ms |
31824 KB |
Output is correct |
28 |
Correct |
49 ms |
31824 KB |
Output is correct |
29 |
Correct |
49 ms |
31824 KB |
Output is correct |
30 |
Correct |
48 ms |
31824 KB |
Output is correct |
31 |
Correct |
43 ms |
31824 KB |
Output is correct |
32 |
Correct |
48 ms |
32072 KB |
Output is correct |
33 |
Correct |
50 ms |
31824 KB |
Output is correct |
34 |
Correct |
39 ms |
31648 KB |
Output is correct |
35 |
Correct |
43 ms |
31824 KB |
Output is correct |
36 |
Correct |
39 ms |
31996 KB |
Output is correct |
37 |
Correct |
47 ms |
31824 KB |
Output is correct |
38 |
Correct |
50 ms |
31824 KB |
Output is correct |
39 |
Correct |
30 ms |
31992 KB |
Output is correct |
40 |
Correct |
31 ms |
31824 KB |
Output is correct |
41 |
Correct |
41 ms |
31824 KB |
Output is correct |
42 |
Correct |
47 ms |
31824 KB |
Output is correct |
43 |
Correct |
40 ms |
31824 KB |
Output is correct |
44 |
Correct |
42 ms |
31824 KB |
Output is correct |
45 |
Correct |
44 ms |
31824 KB |
Output is correct |
46 |
Correct |
51 ms |
31824 KB |
Output is correct |
47 |
Correct |
51 ms |
31824 KB |
Output is correct |
48 |
Correct |
47 ms |
31824 KB |
Output is correct |
49 |
Correct |
45 ms |
31824 KB |
Output is correct |
50 |
Correct |
42 ms |
31992 KB |
Output is correct |
51 |
Correct |
34 ms |
31824 KB |
Output is correct |
52 |
Correct |
51 ms |
31824 KB |
Output is correct |
53 |
Correct |
54 ms |
31824 KB |
Output is correct |
54 |
Correct |
60 ms |
31824 KB |
Output is correct |
55 |
Correct |
55 ms |
31784 KB |
Output is correct |
56 |
Correct |
104 ms |
31824 KB |
Output is correct |
57 |
Correct |
94 ms |
31856 KB |
Output is correct |
58 |
Correct |
93 ms |
31824 KB |
Output is correct |
59 |
Correct |
96 ms |
31824 KB |
Output is correct |
60 |
Incorrect |
151 ms |
31824 KB |
Output isn't correct |
61 |
Halted |
0 ms |
0 KB |
- |