#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define name "main"
const int maxlog=(int)61;
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];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
31824 KB |
Output is correct |
2 |
Correct |
71 ms |
31824 KB |
Output is correct |
3 |
Correct |
70 ms |
31824 KB |
Output is correct |
4 |
Correct |
70 ms |
31824 KB |
Output is correct |
5 |
Correct |
64 ms |
31824 KB |
Output is correct |
6 |
Correct |
60 ms |
31824 KB |
Output is correct |
7 |
Correct |
61 ms |
31824 KB |
Output is correct |
8 |
Correct |
63 ms |
31824 KB |
Output is correct |
9 |
Correct |
64 ms |
31824 KB |
Output is correct |
10 |
Correct |
63 ms |
31824 KB |
Output is correct |
11 |
Correct |
59 ms |
31660 KB |
Output is correct |
12 |
Correct |
48 ms |
31824 KB |
Output is correct |
13 |
Correct |
66 ms |
31824 KB |
Output is correct |
14 |
Incorrect |
65 ms |
31824 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
31824 KB |
Output is correct |
2 |
Correct |
65 ms |
31836 KB |
Output is correct |
3 |
Correct |
72 ms |
31824 KB |
Output is correct |
4 |
Correct |
60 ms |
31824 KB |
Output is correct |
5 |
Correct |
51 ms |
31824 KB |
Output is correct |
6 |
Correct |
74 ms |
31660 KB |
Output is correct |
7 |
Correct |
60 ms |
31824 KB |
Output is correct |
8 |
Correct |
60 ms |
31824 KB |
Output is correct |
9 |
Correct |
67 ms |
31992 KB |
Output is correct |
10 |
Correct |
51 ms |
31824 KB |
Output is correct |
11 |
Correct |
61 ms |
31992 KB |
Output is correct |
12 |
Correct |
66 ms |
31824 KB |
Output is correct |
13 |
Correct |
64 ms |
31824 KB |
Output is correct |
14 |
Incorrect |
63 ms |
31824 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
31824 KB |
Output is correct |
2 |
Correct |
64 ms |
31824 KB |
Output is correct |
3 |
Correct |
74 ms |
31836 KB |
Output is correct |
4 |
Correct |
67 ms |
31996 KB |
Output is correct |
5 |
Correct |
65 ms |
31824 KB |
Output is correct |
6 |
Correct |
72 ms |
31824 KB |
Output is correct |
7 |
Correct |
59 ms |
31824 KB |
Output is correct |
8 |
Correct |
49 ms |
31824 KB |
Output is correct |
9 |
Correct |
62 ms |
31824 KB |
Output is correct |
10 |
Correct |
69 ms |
31824 KB |
Output is correct |
11 |
Correct |
64 ms |
31824 KB |
Output is correct |
12 |
Correct |
75 ms |
31824 KB |
Output is correct |
13 |
Correct |
67 ms |
31824 KB |
Output is correct |
14 |
Correct |
65 ms |
31824 KB |
Output is correct |
15 |
Correct |
63 ms |
31992 KB |
Output is correct |
16 |
Correct |
65 ms |
31836 KB |
Output is correct |
17 |
Correct |
60 ms |
31824 KB |
Output is correct |
18 |
Correct |
75 ms |
31992 KB |
Output is correct |
19 |
Correct |
73 ms |
31824 KB |
Output is correct |
20 |
Correct |
76 ms |
31824 KB |
Output is correct |
21 |
Correct |
81 ms |
31824 KB |
Output is correct |
22 |
Correct |
75 ms |
32072 KB |
Output is correct |
23 |
Correct |
74 ms |
31824 KB |
Output is correct |
24 |
Correct |
73 ms |
31824 KB |
Output is correct |
25 |
Correct |
68 ms |
31824 KB |
Output is correct |
26 |
Correct |
72 ms |
31824 KB |
Output is correct |
27 |
Correct |
68 ms |
31824 KB |
Output is correct |
28 |
Correct |
65 ms |
31824 KB |
Output is correct |
29 |
Correct |
64 ms |
31824 KB |
Output is correct |
30 |
Correct |
71 ms |
31824 KB |
Output is correct |
31 |
Correct |
64 ms |
31824 KB |
Output is correct |
32 |
Correct |
67 ms |
31824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
31824 KB |
Output is correct |
2 |
Correct |
72 ms |
31824 KB |
Output is correct |
3 |
Correct |
71 ms |
31824 KB |
Output is correct |
4 |
Correct |
77 ms |
31824 KB |
Output is correct |
5 |
Correct |
75 ms |
31824 KB |
Output is correct |
6 |
Correct |
77 ms |
31824 KB |
Output is correct |
7 |
Correct |
78 ms |
31996 KB |
Output is correct |
8 |
Correct |
72 ms |
31824 KB |
Output is correct |
9 |
Correct |
68 ms |
31824 KB |
Output is correct |
10 |
Correct |
66 ms |
31824 KB |
Output is correct |
11 |
Correct |
72 ms |
31620 KB |
Output is correct |
12 |
Correct |
76 ms |
31824 KB |
Output is correct |
13 |
Correct |
81 ms |
31824 KB |
Output is correct |
14 |
Incorrect |
78 ms |
31824 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
31824 KB |
Output is correct |
2 |
Correct |
65 ms |
32076 KB |
Output is correct |
3 |
Correct |
69 ms |
31996 KB |
Output is correct |
4 |
Correct |
69 ms |
31824 KB |
Output is correct |
5 |
Correct |
71 ms |
31824 KB |
Output is correct |
6 |
Correct |
70 ms |
31824 KB |
Output is correct |
7 |
Correct |
74 ms |
31840 KB |
Output is correct |
8 |
Correct |
70 ms |
31824 KB |
Output is correct |
9 |
Correct |
83 ms |
31824 KB |
Output is correct |
10 |
Correct |
71 ms |
32076 KB |
Output is correct |
11 |
Correct |
56 ms |
31824 KB |
Output is correct |
12 |
Correct |
67 ms |
31824 KB |
Output is correct |
13 |
Correct |
70 ms |
31824 KB |
Output is correct |
14 |
Correct |
67 ms |
31824 KB |
Output is correct |
15 |
Correct |
59 ms |
31824 KB |
Output is correct |
16 |
Correct |
70 ms |
31628 KB |
Output is correct |
17 |
Correct |
78 ms |
31824 KB |
Output is correct |
18 |
Correct |
62 ms |
31824 KB |
Output is correct |
19 |
Correct |
73 ms |
31824 KB |
Output is correct |
20 |
Correct |
66 ms |
31824 KB |
Output is correct |
21 |
Correct |
69 ms |
31824 KB |
Output is correct |
22 |
Correct |
81 ms |
31844 KB |
Output is correct |
23 |
Correct |
82 ms |
31824 KB |
Output is correct |
24 |
Correct |
72 ms |
31824 KB |
Output is correct |
25 |
Correct |
71 ms |
31824 KB |
Output is correct |
26 |
Correct |
71 ms |
31824 KB |
Output is correct |
27 |
Correct |
67 ms |
31824 KB |
Output is correct |
28 |
Correct |
71 ms |
31824 KB |
Output is correct |
29 |
Correct |
71 ms |
31824 KB |
Output is correct |
30 |
Correct |
72 ms |
31676 KB |
Output is correct |
31 |
Correct |
73 ms |
31824 KB |
Output is correct |
32 |
Correct |
77 ms |
31824 KB |
Output is correct |
33 |
Correct |
77 ms |
31824 KB |
Output is correct |
34 |
Correct |
71 ms |
31824 KB |
Output is correct |
35 |
Correct |
73 ms |
31824 KB |
Output is correct |
36 |
Correct |
81 ms |
31824 KB |
Output is correct |
37 |
Correct |
74 ms |
31824 KB |
Output is correct |
38 |
Correct |
72 ms |
31824 KB |
Output is correct |
39 |
Correct |
73 ms |
31824 KB |
Output is correct |
40 |
Correct |
74 ms |
31640 KB |
Output is correct |
41 |
Correct |
70 ms |
31824 KB |
Output is correct |
42 |
Correct |
75 ms |
31828 KB |
Output is correct |
43 |
Correct |
80 ms |
31824 KB |
Output is correct |
44 |
Correct |
71 ms |
31824 KB |
Output is correct |
45 |
Correct |
76 ms |
31824 KB |
Output is correct |
46 |
Correct |
73 ms |
31824 KB |
Output is correct |
47 |
Correct |
79 ms |
31824 KB |
Output is correct |
48 |
Correct |
80 ms |
31824 KB |
Output is correct |
49 |
Correct |
82 ms |
31824 KB |
Output is correct |
50 |
Correct |
72 ms |
31824 KB |
Output is correct |
51 |
Correct |
80 ms |
31824 KB |
Output is correct |
52 |
Correct |
85 ms |
31840 KB |
Output is correct |
53 |
Correct |
96 ms |
31824 KB |
Output is correct |
54 |
Correct |
111 ms |
31824 KB |
Output is correct |
55 |
Correct |
106 ms |
31824 KB |
Output is correct |
56 |
Correct |
227 ms |
31824 KB |
Output is correct |
57 |
Correct |
205 ms |
31824 KB |
Output is correct |
58 |
Correct |
202 ms |
31836 KB |
Output is correct |
59 |
Correct |
200 ms |
31824 KB |
Output is correct |
60 |
Correct |
217 ms |
32072 KB |
Output is correct |
61 |
Correct |
62 ms |
31836 KB |
Output is correct |
62 |
Correct |
86 ms |
31824 KB |
Output is correct |
63 |
Correct |
118 ms |
31824 KB |
Output is correct |
64 |
Correct |
104 ms |
31824 KB |
Output is correct |
65 |
Correct |
153 ms |
31852 KB |
Output is correct |
66 |
Correct |
161 ms |
31824 KB |
Output is correct |
67 |
Correct |
193 ms |
31992 KB |
Output is correct |
68 |
Correct |
190 ms |
31824 KB |
Output is correct |
69 |
Correct |
184 ms |
31824 KB |
Output is correct |