#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define N (int)(1e5+10)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define inf mod
#define endl '\n'
#define sag (sol|1)
#define sol (root<<1)
#define ort ((bas+son)>>1)
#define bit(x,y) ((x>>y)&1)
#define int long long
int dp1[2004],dp2[105][105];
int i,j,k,n,m,x,y,z,H[2005][2005];
int temp[2005][2005],pre[2005];
int a,b,A[2004],ans;
bool f1(){
memset(dp1,5,sizeof dp1);
dp1[n+1] = 0;
for(int x=n ; x>=1 ; x--)
for(int y=n ; y>=x ; y--)
if(H[x][y])
dp1[x] = min(dp1[y+1]+1,dp1[x]);
return dp1[1]<=b;
}
bool f2(){
memset(dp2,0,sizeof dp2);
dp2[n+1][0] = 1;
for(int x=n ; x>=1 ; x--)
for(int k=b ; k>=1 ; k--)
for(int y=n ; y>=x ; y--)
if(H[x][y])
dp2[x][k] |= dp2[y+1][k-1];
bool ans=0;
for(int i=a ; i<=b ; i++)
ans |= dp2[1][i];
return ans;
}
main(){
cin >> n >> a >> b;
for(i=1 ; i<=n ; i++){
scanf("%lld",A+i);
pre[i] = pre[i-1] + A[i];
}
for(i=1 ; i<=n ; i++)
for(j=i ; j<=n ; j++)
H[i][j] = 1;
for(i=40 ; i>=0 ; i--){
for(int x=1 ; x<=n ; x++)
for(int y=x ; y<=n ; y++) {
temp[x][y] = H[x][y];
if(H[x][y] and ((1ll << i) & (pre[y] - pre[x - 1])))
H[x][y] = 0;
}
if(a == 1 and f1())
continue;
if(a != 1 and f2())
continue;
ans += (1LL<<i);
for(int x=1 ; x<=n ; x++)
for(int y=x ; y<=n ; y++)
H[x][y] = temp[x][y];
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64668 KB |
Output is correct |
2 |
Correct |
0 ms |
64668 KB |
Output is correct |
3 |
Correct |
0 ms |
64668 KB |
Output is correct |
4 |
Correct |
0 ms |
64668 KB |
Output is correct |
5 |
Correct |
0 ms |
64668 KB |
Output is correct |
6 |
Correct |
0 ms |
64668 KB |
Output is correct |
7 |
Correct |
0 ms |
64668 KB |
Output is correct |
8 |
Correct |
0 ms |
64668 KB |
Output is correct |
9 |
Correct |
0 ms |
64668 KB |
Output is correct |
10 |
Correct |
0 ms |
64668 KB |
Output is correct |
11 |
Correct |
0 ms |
64668 KB |
Output is correct |
12 |
Correct |
0 ms |
64668 KB |
Output is correct |
13 |
Correct |
0 ms |
64668 KB |
Output is correct |
14 |
Correct |
0 ms |
64668 KB |
Output is correct |
15 |
Correct |
0 ms |
64668 KB |
Output is correct |
16 |
Correct |
0 ms |
64668 KB |
Output is correct |
17 |
Correct |
0 ms |
64668 KB |
Output is correct |
18 |
Correct |
0 ms |
64668 KB |
Output is correct |
19 |
Correct |
0 ms |
64668 KB |
Output is correct |
20 |
Correct |
0 ms |
64668 KB |
Output is correct |
21 |
Correct |
0 ms |
64668 KB |
Output is correct |
22 |
Correct |
0 ms |
64668 KB |
Output is correct |
23 |
Correct |
0 ms |
64668 KB |
Output is correct |
24 |
Correct |
0 ms |
64668 KB |
Output is correct |
25 |
Correct |
0 ms |
64668 KB |
Output is correct |
26 |
Correct |
0 ms |
64668 KB |
Output is correct |
27 |
Correct |
0 ms |
64668 KB |
Output is correct |
28 |
Correct |
0 ms |
64668 KB |
Output is correct |
29 |
Correct |
0 ms |
64668 KB |
Output is correct |
30 |
Correct |
0 ms |
64668 KB |
Output is correct |
31 |
Correct |
0 ms |
64668 KB |
Output is correct |
32 |
Correct |
0 ms |
64668 KB |
Output is correct |
33 |
Correct |
0 ms |
64668 KB |
Output is correct |
34 |
Correct |
0 ms |
64668 KB |
Output is correct |
35 |
Correct |
0 ms |
64668 KB |
Output is correct |
36 |
Correct |
0 ms |
64668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
64668 KB |
Output is correct |
2 |
Correct |
0 ms |
64668 KB |
Output is correct |
3 |
Correct |
0 ms |
64668 KB |
Output is correct |
4 |
Correct |
0 ms |
64668 KB |
Output is correct |
5 |
Correct |
0 ms |
64668 KB |
Output is correct |
6 |
Correct |
0 ms |
64668 KB |
Output is correct |
7 |
Correct |
0 ms |
64668 KB |
Output is correct |
8 |
Correct |
0 ms |
64668 KB |
Output is correct |
9 |
Correct |
0 ms |
64668 KB |
Output is correct |
10 |
Correct |
0 ms |
64668 KB |
Output is correct |
11 |
Correct |
0 ms |
64668 KB |
Output is correct |
12 |
Correct |
0 ms |
64668 KB |
Output is correct |
13 |
Correct |
1 ms |
64668 KB |
Output is correct |
14 |
Correct |
0 ms |
64668 KB |
Output is correct |
15 |
Correct |
0 ms |
64668 KB |
Output is correct |
16 |
Correct |
0 ms |
64668 KB |
Output is correct |
17 |
Correct |
0 ms |
64668 KB |
Output is correct |
18 |
Correct |
0 ms |
64668 KB |
Output is correct |
19 |
Correct |
0 ms |
64668 KB |
Output is correct |
20 |
Correct |
0 ms |
64668 KB |
Output is correct |
21 |
Correct |
0 ms |
64668 KB |
Output is correct |
22 |
Correct |
0 ms |
64668 KB |
Output is correct |
23 |
Correct |
0 ms |
64668 KB |
Output is correct |
24 |
Correct |
0 ms |
64668 KB |
Output is correct |
25 |
Correct |
0 ms |
64668 KB |
Output is correct |
26 |
Correct |
0 ms |
64668 KB |
Output is correct |
27 |
Correct |
0 ms |
64668 KB |
Output is correct |
28 |
Correct |
0 ms |
64668 KB |
Output is correct |
29 |
Correct |
0 ms |
64668 KB |
Output is correct |
30 |
Correct |
1 ms |
64668 KB |
Output is correct |
31 |
Correct |
0 ms |
64668 KB |
Output is correct |
32 |
Correct |
0 ms |
64668 KB |
Output is correct |
33 |
Correct |
0 ms |
64668 KB |
Output is correct |
34 |
Correct |
0 ms |
64668 KB |
Output is correct |
35 |
Correct |
1 ms |
64668 KB |
Output is correct |
36 |
Correct |
0 ms |
64668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64668 KB |
Output is correct |
2 |
Correct |
0 ms |
64668 KB |
Output is correct |
3 |
Correct |
0 ms |
64668 KB |
Output is correct |
4 |
Correct |
0 ms |
64668 KB |
Output is correct |
5 |
Correct |
0 ms |
64668 KB |
Output is correct |
6 |
Correct |
1 ms |
64668 KB |
Output is correct |
7 |
Correct |
1 ms |
64668 KB |
Output is correct |
8 |
Correct |
1 ms |
64668 KB |
Output is correct |
9 |
Correct |
0 ms |
64668 KB |
Output is correct |
10 |
Correct |
0 ms |
64668 KB |
Output is correct |
11 |
Correct |
1 ms |
64668 KB |
Output is correct |
12 |
Correct |
0 ms |
64668 KB |
Output is correct |
13 |
Correct |
1 ms |
64668 KB |
Output is correct |
14 |
Correct |
0 ms |
64668 KB |
Output is correct |
15 |
Correct |
0 ms |
64668 KB |
Output is correct |
16 |
Correct |
0 ms |
64668 KB |
Output is correct |
17 |
Correct |
0 ms |
64668 KB |
Output is correct |
18 |
Correct |
0 ms |
64668 KB |
Output is correct |
19 |
Correct |
0 ms |
64668 KB |
Output is correct |
20 |
Correct |
0 ms |
64668 KB |
Output is correct |
21 |
Correct |
0 ms |
64668 KB |
Output is correct |
22 |
Correct |
0 ms |
64668 KB |
Output is correct |
23 |
Correct |
0 ms |
64668 KB |
Output is correct |
24 |
Correct |
1 ms |
64668 KB |
Output is correct |
25 |
Correct |
0 ms |
64668 KB |
Output is correct |
26 |
Correct |
0 ms |
64668 KB |
Output is correct |
27 |
Correct |
2 ms |
64668 KB |
Output is correct |
28 |
Correct |
0 ms |
64668 KB |
Output is correct |
29 |
Correct |
2 ms |
64668 KB |
Output is correct |
30 |
Correct |
0 ms |
64668 KB |
Output is correct |
31 |
Correct |
0 ms |
64668 KB |
Output is correct |
32 |
Correct |
0 ms |
64668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64668 KB |
Output is correct |
2 |
Correct |
0 ms |
64668 KB |
Output is correct |
3 |
Correct |
0 ms |
64668 KB |
Output is correct |
4 |
Correct |
0 ms |
64668 KB |
Output is correct |
5 |
Correct |
0 ms |
64668 KB |
Output is correct |
6 |
Correct |
0 ms |
64668 KB |
Output is correct |
7 |
Correct |
0 ms |
64668 KB |
Output is correct |
8 |
Correct |
0 ms |
64668 KB |
Output is correct |
9 |
Correct |
0 ms |
64668 KB |
Output is correct |
10 |
Correct |
0 ms |
64668 KB |
Output is correct |
11 |
Correct |
0 ms |
64668 KB |
Output is correct |
12 |
Correct |
0 ms |
64668 KB |
Output is correct |
13 |
Correct |
0 ms |
64668 KB |
Output is correct |
14 |
Correct |
0 ms |
64668 KB |
Output is correct |
15 |
Correct |
0 ms |
64668 KB |
Output is correct |
16 |
Correct |
0 ms |
64668 KB |
Output is correct |
17 |
Correct |
0 ms |
64668 KB |
Output is correct |
18 |
Correct |
0 ms |
64668 KB |
Output is correct |
19 |
Correct |
0 ms |
64668 KB |
Output is correct |
20 |
Correct |
0 ms |
64668 KB |
Output is correct |
21 |
Correct |
0 ms |
64668 KB |
Output is correct |
22 |
Correct |
0 ms |
64668 KB |
Output is correct |
23 |
Correct |
0 ms |
64668 KB |
Output is correct |
24 |
Correct |
0 ms |
64668 KB |
Output is correct |
25 |
Correct |
0 ms |
64668 KB |
Output is correct |
26 |
Correct |
0 ms |
64668 KB |
Output is correct |
27 |
Correct |
0 ms |
64668 KB |
Output is correct |
28 |
Correct |
0 ms |
64668 KB |
Output is correct |
29 |
Correct |
0 ms |
64668 KB |
Output is correct |
30 |
Correct |
0 ms |
64668 KB |
Output is correct |
31 |
Correct |
0 ms |
64668 KB |
Output is correct |
32 |
Correct |
0 ms |
64668 KB |
Output is correct |
33 |
Correct |
0 ms |
64668 KB |
Output is correct |
34 |
Correct |
0 ms |
64668 KB |
Output is correct |
35 |
Correct |
0 ms |
64668 KB |
Output is correct |
36 |
Correct |
0 ms |
64668 KB |
Output is correct |
37 |
Correct |
0 ms |
64668 KB |
Output is correct |
38 |
Correct |
0 ms |
64668 KB |
Output is correct |
39 |
Correct |
0 ms |
64668 KB |
Output is correct |
40 |
Correct |
0 ms |
64668 KB |
Output is correct |
41 |
Correct |
0 ms |
64668 KB |
Output is correct |
42 |
Correct |
0 ms |
64668 KB |
Output is correct |
43 |
Correct |
1 ms |
64668 KB |
Output is correct |
44 |
Correct |
1 ms |
64668 KB |
Output is correct |
45 |
Correct |
0 ms |
64668 KB |
Output is correct |
46 |
Correct |
0 ms |
64668 KB |
Output is correct |
47 |
Correct |
0 ms |
64668 KB |
Output is correct |
48 |
Correct |
0 ms |
64668 KB |
Output is correct |
49 |
Correct |
1 ms |
64668 KB |
Output is correct |
50 |
Correct |
0 ms |
64668 KB |
Output is correct |
51 |
Correct |
2 ms |
64668 KB |
Output is correct |
52 |
Correct |
0 ms |
64668 KB |
Output is correct |
53 |
Correct |
2 ms |
64668 KB |
Output is correct |
54 |
Correct |
0 ms |
64668 KB |
Output is correct |
55 |
Correct |
2 ms |
64668 KB |
Output is correct |
56 |
Correct |
1 ms |
64668 KB |
Output is correct |
57 |
Correct |
0 ms |
64668 KB |
Output is correct |
58 |
Correct |
0 ms |
64668 KB |
Output is correct |
59 |
Correct |
0 ms |
64668 KB |
Output is correct |
60 |
Correct |
0 ms |
64668 KB |
Output is correct |
61 |
Correct |
0 ms |
64668 KB |
Output is correct |
62 |
Correct |
0 ms |
64668 KB |
Output is correct |
63 |
Correct |
0 ms |
64668 KB |
Output is correct |
64 |
Correct |
40 ms |
64668 KB |
Output is correct |
65 |
Correct |
3 ms |
64668 KB |
Output is correct |
66 |
Correct |
3 ms |
64668 KB |
Output is correct |
67 |
Correct |
7 ms |
64668 KB |
Output is correct |
68 |
Correct |
17 ms |
64668 KB |
Output is correct |
69 |
Correct |
35 ms |
64668 KB |
Output is correct |
70 |
Correct |
30 ms |
64668 KB |
Output is correct |
71 |
Correct |
0 ms |
64668 KB |
Output is correct |
72 |
Correct |
34 ms |
64668 KB |
Output is correct |
73 |
Correct |
28 ms |
64668 KB |
Output is correct |
74 |
Correct |
25 ms |
64668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64668 KB |
Output is correct |
2 |
Correct |
0 ms |
64668 KB |
Output is correct |
3 |
Correct |
0 ms |
64668 KB |
Output is correct |
4 |
Correct |
0 ms |
64668 KB |
Output is correct |
5 |
Correct |
0 ms |
64668 KB |
Output is correct |
6 |
Correct |
0 ms |
64668 KB |
Output is correct |
7 |
Correct |
0 ms |
64668 KB |
Output is correct |
8 |
Correct |
0 ms |
64668 KB |
Output is correct |
9 |
Correct |
0 ms |
64668 KB |
Output is correct |
10 |
Correct |
0 ms |
64668 KB |
Output is correct |
11 |
Correct |
0 ms |
64668 KB |
Output is correct |
12 |
Correct |
0 ms |
64668 KB |
Output is correct |
13 |
Correct |
0 ms |
64668 KB |
Output is correct |
14 |
Correct |
0 ms |
64668 KB |
Output is correct |
15 |
Correct |
0 ms |
64668 KB |
Output is correct |
16 |
Correct |
0 ms |
64668 KB |
Output is correct |
17 |
Correct |
0 ms |
64668 KB |
Output is correct |
18 |
Correct |
0 ms |
64668 KB |
Output is correct |
19 |
Correct |
0 ms |
64668 KB |
Output is correct |
20 |
Correct |
0 ms |
64668 KB |
Output is correct |
21 |
Correct |
0 ms |
64668 KB |
Output is correct |
22 |
Correct |
0 ms |
64668 KB |
Output is correct |
23 |
Correct |
0 ms |
64668 KB |
Output is correct |
24 |
Correct |
0 ms |
64668 KB |
Output is correct |
25 |
Correct |
0 ms |
64668 KB |
Output is correct |
26 |
Correct |
0 ms |
64668 KB |
Output is correct |
27 |
Correct |
0 ms |
64668 KB |
Output is correct |
28 |
Correct |
1 ms |
64668 KB |
Output is correct |
29 |
Correct |
0 ms |
64668 KB |
Output is correct |
30 |
Correct |
1 ms |
64668 KB |
Output is correct |
31 |
Correct |
0 ms |
64668 KB |
Output is correct |
32 |
Correct |
0 ms |
64668 KB |
Output is correct |
33 |
Correct |
0 ms |
64668 KB |
Output is correct |
34 |
Correct |
0 ms |
64668 KB |
Output is correct |
35 |
Correct |
0 ms |
64668 KB |
Output is correct |
36 |
Correct |
0 ms |
64668 KB |
Output is correct |
37 |
Correct |
0 ms |
64668 KB |
Output is correct |
38 |
Correct |
0 ms |
64668 KB |
Output is correct |
39 |
Correct |
0 ms |
64668 KB |
Output is correct |
40 |
Correct |
2 ms |
64668 KB |
Output is correct |
41 |
Correct |
0 ms |
64668 KB |
Output is correct |
42 |
Correct |
0 ms |
64668 KB |
Output is correct |
43 |
Correct |
0 ms |
64668 KB |
Output is correct |
44 |
Correct |
2 ms |
64668 KB |
Output is correct |
45 |
Correct |
0 ms |
64668 KB |
Output is correct |
46 |
Correct |
0 ms |
64668 KB |
Output is correct |
47 |
Correct |
0 ms |
64668 KB |
Output is correct |
48 |
Correct |
0 ms |
64668 KB |
Output is correct |
49 |
Correct |
2 ms |
64668 KB |
Output is correct |
50 |
Correct |
0 ms |
64668 KB |
Output is correct |
51 |
Correct |
0 ms |
64668 KB |
Output is correct |
52 |
Correct |
25 ms |
64668 KB |
Output is correct |
53 |
Correct |
40 ms |
64668 KB |
Output is correct |
54 |
Correct |
87 ms |
64668 KB |
Output is correct |
55 |
Correct |
76 ms |
64668 KB |
Output is correct |
56 |
Correct |
356 ms |
64668 KB |
Output is correct |
57 |
Correct |
355 ms |
64668 KB |
Output is correct |
58 |
Correct |
327 ms |
64668 KB |
Output is correct |
59 |
Correct |
291 ms |
64668 KB |
Output is correct |
60 |
Correct |
312 ms |
64668 KB |
Output is correct |
61 |
Correct |
2 ms |
64668 KB |
Output is correct |
62 |
Correct |
40 ms |
64668 KB |
Output is correct |
63 |
Correct |
84 ms |
64668 KB |
Output is correct |
64 |
Correct |
69 ms |
64668 KB |
Output is correct |
65 |
Correct |
169 ms |
64668 KB |
Output is correct |
66 |
Correct |
272 ms |
64668 KB |
Output is correct |
67 |
Correct |
320 ms |
64668 KB |
Output is correct |
68 |
Correct |
373 ms |
64668 KB |
Output is correct |
69 |
Correct |
356 ms |
64668 KB |
Output is correct |