#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2010;
const int MAXM = 110;
int dp[MAXN],N,A,B;
bool tab[MAXM][MAXM],possivel;
ll soma[MAXN],proibido,atual;
ll calc(ll a,ll b){return soma[b] - soma[a-1];}
int solve(int pos){
if(dp[pos] != -1) return dp[pos];
if(pos == N + 1) return dp[pos] = 0;
int best = MAXN;
for(int quebra = pos;quebra<=N;quebra++){
if((calc(pos,quebra)) & proibido) continue;
best = min(best, 1 + solve(quebra+1));
}
return dp[pos] = best;
}
void check(int pos,int resta){
if(possivel) return;
if(tab[pos][resta]) return;
tab[pos][resta] = true;
if(pos == N + 1 && resta == 0) possivel = true;
if(resta == 0 || pos == N+1) return;
for(int quebra = pos;quebra<=N;quebra++){
if((calc(pos,quebra)) & proibido) continue;
check(quebra+1,resta - 1);
}
}
int main(){
cin >> N >> A >> B;
if(A == 1){
for(int i = 1;i<=N;i++){
cin >> soma[i];
soma[i] += soma[i-1];
}
for(ll i = 41;i>=0;i--){
proibido |= (1LL << i);
memset(dp,-1,sizeof(dp));
if(solve(1) > B){
proibido ^= (1LL << i);
atual |= (1LL << i);
}
}
cout << atual << endl;
}
else{
for(int i = 1;i<=N;i++){
cin >> soma[i];
soma[i] += soma[i-1];
}
for(ll i = 37;i>=0;i--){
proibido |= (1LL << i);
memset(tab,false,sizeof(tab));
possivel = false;
for(int j = A;j<=B;j++) check(1,j);
if(!possivel){
proibido ^= (1LL << i);
atual |= (1LL << i);
}
}
cout << atual << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
528 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
1 ms |
620 KB |
Output is correct |
18 |
Correct |
1 ms |
620 KB |
Output is correct |
19 |
Correct |
1 ms |
624 KB |
Output is correct |
20 |
Correct |
1 ms |
624 KB |
Output is correct |
21 |
Correct |
2 ms |
624 KB |
Output is correct |
22 |
Correct |
1 ms |
624 KB |
Output is correct |
23 |
Correct |
2 ms |
624 KB |
Output is correct |
24 |
Correct |
1 ms |
624 KB |
Output is correct |
25 |
Correct |
2 ms |
624 KB |
Output is correct |
26 |
Correct |
2 ms |
624 KB |
Output is correct |
27 |
Correct |
1 ms |
624 KB |
Output is correct |
28 |
Correct |
2 ms |
624 KB |
Output is correct |
29 |
Correct |
2 ms |
624 KB |
Output is correct |
30 |
Correct |
2 ms |
624 KB |
Output is correct |
31 |
Correct |
2 ms |
624 KB |
Output is correct |
32 |
Correct |
1 ms |
624 KB |
Output is correct |
33 |
Correct |
1 ms |
624 KB |
Output is correct |
34 |
Correct |
2 ms |
624 KB |
Output is correct |
35 |
Correct |
2 ms |
624 KB |
Output is correct |
36 |
Correct |
2 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
624 KB |
Output is correct |
2 |
Correct |
1 ms |
624 KB |
Output is correct |
3 |
Correct |
1 ms |
624 KB |
Output is correct |
4 |
Correct |
2 ms |
624 KB |
Output is correct |
5 |
Correct |
2 ms |
624 KB |
Output is correct |
6 |
Correct |
2 ms |
624 KB |
Output is correct |
7 |
Correct |
1 ms |
624 KB |
Output is correct |
8 |
Correct |
2 ms |
624 KB |
Output is correct |
9 |
Correct |
2 ms |
624 KB |
Output is correct |
10 |
Correct |
1 ms |
624 KB |
Output is correct |
11 |
Correct |
1 ms |
624 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
1 ms |
624 KB |
Output is correct |
14 |
Correct |
1 ms |
624 KB |
Output is correct |
15 |
Correct |
1 ms |
624 KB |
Output is correct |
16 |
Correct |
1 ms |
624 KB |
Output is correct |
17 |
Correct |
1 ms |
624 KB |
Output is correct |
18 |
Correct |
1 ms |
624 KB |
Output is correct |
19 |
Correct |
1 ms |
624 KB |
Output is correct |
20 |
Correct |
1 ms |
624 KB |
Output is correct |
21 |
Correct |
2 ms |
624 KB |
Output is correct |
22 |
Correct |
1 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
1 ms |
720 KB |
Output is correct |
26 |
Correct |
2 ms |
720 KB |
Output is correct |
27 |
Correct |
2 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
2 ms |
740 KB |
Output is correct |
31 |
Correct |
2 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
2 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
740 KB |
Output is correct |
2 |
Correct |
1 ms |
740 KB |
Output is correct |
3 |
Correct |
2 ms |
740 KB |
Output is correct |
4 |
Correct |
2 ms |
740 KB |
Output is correct |
5 |
Correct |
1 ms |
740 KB |
Output is correct |
6 |
Correct |
2 ms |
740 KB |
Output is correct |
7 |
Correct |
1 ms |
740 KB |
Output is correct |
8 |
Correct |
1 ms |
740 KB |
Output is correct |
9 |
Correct |
1 ms |
740 KB |
Output is correct |
10 |
Correct |
1 ms |
740 KB |
Output is correct |
11 |
Correct |
1 ms |
740 KB |
Output is correct |
12 |
Correct |
2 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
1 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
2 ms |
740 KB |
Output is correct |
23 |
Correct |
2 ms |
740 KB |
Output is correct |
24 |
Correct |
2 ms |
740 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
3 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
2 ms |
740 KB |
Output is correct |
31 |
Correct |
3 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
740 KB |
Output is correct |
2 |
Correct |
2 ms |
740 KB |
Output is correct |
3 |
Correct |
2 ms |
740 KB |
Output is correct |
4 |
Correct |
2 ms |
740 KB |
Output is correct |
5 |
Correct |
1 ms |
740 KB |
Output is correct |
6 |
Correct |
2 ms |
740 KB |
Output is correct |
7 |
Correct |
2 ms |
740 KB |
Output is correct |
8 |
Correct |
2 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
2 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
1 ms |
740 KB |
Output is correct |
15 |
Correct |
1 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
1 ms |
740 KB |
Output is correct |
18 |
Correct |
1 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
1 ms |
740 KB |
Output is correct |
23 |
Correct |
2 ms |
740 KB |
Output is correct |
24 |
Correct |
2 ms |
740 KB |
Output is correct |
25 |
Correct |
1 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
1 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
2 ms |
740 KB |
Output is correct |
31 |
Correct |
2 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
2 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
2 ms |
740 KB |
Output is correct |
38 |
Correct |
1 ms |
740 KB |
Output is correct |
39 |
Correct |
2 ms |
740 KB |
Output is correct |
40 |
Correct |
2 ms |
740 KB |
Output is correct |
41 |
Correct |
2 ms |
740 KB |
Output is correct |
42 |
Correct |
2 ms |
740 KB |
Output is correct |
43 |
Correct |
2 ms |
740 KB |
Output is correct |
44 |
Correct |
2 ms |
740 KB |
Output is correct |
45 |
Correct |
2 ms |
740 KB |
Output is correct |
46 |
Correct |
2 ms |
740 KB |
Output is correct |
47 |
Correct |
2 ms |
740 KB |
Output is correct |
48 |
Correct |
2 ms |
740 KB |
Output is correct |
49 |
Correct |
2 ms |
740 KB |
Output is correct |
50 |
Correct |
2 ms |
740 KB |
Output is correct |
51 |
Correct |
3 ms |
740 KB |
Output is correct |
52 |
Correct |
2 ms |
740 KB |
Output is correct |
53 |
Correct |
2 ms |
740 KB |
Output is correct |
54 |
Correct |
2 ms |
740 KB |
Output is correct |
55 |
Correct |
2 ms |
740 KB |
Output is correct |
56 |
Correct |
2 ms |
740 KB |
Output is correct |
57 |
Correct |
2 ms |
740 KB |
Output is correct |
58 |
Correct |
2 ms |
740 KB |
Output is correct |
59 |
Correct |
2 ms |
740 KB |
Output is correct |
60 |
Correct |
2 ms |
740 KB |
Output is correct |
61 |
Correct |
2 ms |
740 KB |
Output is correct |
62 |
Correct |
2 ms |
740 KB |
Output is correct |
63 |
Correct |
2 ms |
740 KB |
Output is correct |
64 |
Correct |
2 ms |
740 KB |
Output is correct |
65 |
Correct |
2 ms |
740 KB |
Output is correct |
66 |
Correct |
2 ms |
740 KB |
Output is correct |
67 |
Correct |
2 ms |
740 KB |
Output is correct |
68 |
Correct |
3 ms |
740 KB |
Output is correct |
69 |
Correct |
2 ms |
796 KB |
Output is correct |
70 |
Correct |
6 ms |
796 KB |
Output is correct |
71 |
Correct |
1 ms |
796 KB |
Output is correct |
72 |
Correct |
7 ms |
840 KB |
Output is correct |
73 |
Correct |
5 ms |
840 KB |
Output is correct |
74 |
Correct |
7 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
840 KB |
Output is correct |
2 |
Correct |
2 ms |
840 KB |
Output is correct |
3 |
Correct |
2 ms |
840 KB |
Output is correct |
4 |
Correct |
2 ms |
840 KB |
Output is correct |
5 |
Correct |
2 ms |
840 KB |
Output is correct |
6 |
Correct |
1 ms |
840 KB |
Output is correct |
7 |
Correct |
1 ms |
840 KB |
Output is correct |
8 |
Correct |
2 ms |
840 KB |
Output is correct |
9 |
Correct |
2 ms |
840 KB |
Output is correct |
10 |
Correct |
1 ms |
840 KB |
Output is correct |
11 |
Correct |
1 ms |
840 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
2 ms |
840 KB |
Output is correct |
14 |
Correct |
2 ms |
840 KB |
Output is correct |
15 |
Correct |
1 ms |
840 KB |
Output is correct |
16 |
Correct |
2 ms |
840 KB |
Output is correct |
17 |
Correct |
2 ms |
840 KB |
Output is correct |
18 |
Correct |
2 ms |
840 KB |
Output is correct |
19 |
Correct |
2 ms |
840 KB |
Output is correct |
20 |
Correct |
2 ms |
840 KB |
Output is correct |
21 |
Correct |
2 ms |
840 KB |
Output is correct |
22 |
Correct |
1 ms |
840 KB |
Output is correct |
23 |
Correct |
2 ms |
840 KB |
Output is correct |
24 |
Correct |
1 ms |
840 KB |
Output is correct |
25 |
Correct |
2 ms |
840 KB |
Output is correct |
26 |
Correct |
2 ms |
840 KB |
Output is correct |
27 |
Correct |
2 ms |
840 KB |
Output is correct |
28 |
Correct |
2 ms |
840 KB |
Output is correct |
29 |
Correct |
2 ms |
840 KB |
Output is correct |
30 |
Correct |
2 ms |
840 KB |
Output is correct |
31 |
Correct |
2 ms |
840 KB |
Output is correct |
32 |
Correct |
2 ms |
880 KB |
Output is correct |
33 |
Correct |
2 ms |
880 KB |
Output is correct |
34 |
Correct |
2 ms |
880 KB |
Output is correct |
35 |
Correct |
2 ms |
880 KB |
Output is correct |
36 |
Correct |
2 ms |
880 KB |
Output is correct |
37 |
Correct |
2 ms |
880 KB |
Output is correct |
38 |
Correct |
2 ms |
880 KB |
Output is correct |
39 |
Correct |
2 ms |
880 KB |
Output is correct |
40 |
Correct |
2 ms |
880 KB |
Output is correct |
41 |
Correct |
2 ms |
880 KB |
Output is correct |
42 |
Correct |
2 ms |
880 KB |
Output is correct |
43 |
Correct |
2 ms |
880 KB |
Output is correct |
44 |
Correct |
2 ms |
880 KB |
Output is correct |
45 |
Correct |
2 ms |
880 KB |
Output is correct |
46 |
Correct |
3 ms |
880 KB |
Output is correct |
47 |
Correct |
3 ms |
880 KB |
Output is correct |
48 |
Correct |
2 ms |
880 KB |
Output is correct |
49 |
Correct |
2 ms |
880 KB |
Output is correct |
50 |
Correct |
2 ms |
880 KB |
Output is correct |
51 |
Correct |
2 ms |
880 KB |
Output is correct |
52 |
Correct |
11 ms |
880 KB |
Output is correct |
53 |
Correct |
11 ms |
884 KB |
Output is correct |
54 |
Correct |
35 ms |
884 KB |
Output is correct |
55 |
Correct |
47 ms |
884 KB |
Output is correct |
56 |
Correct |
60 ms |
884 KB |
Output is correct |
57 |
Correct |
57 ms |
884 KB |
Output is correct |
58 |
Correct |
63 ms |
892 KB |
Output is correct |
59 |
Correct |
86 ms |
892 KB |
Output is correct |
60 |
Correct |
67 ms |
892 KB |
Output is correct |
61 |
Correct |
2 ms |
892 KB |
Output is correct |
62 |
Correct |
10 ms |
892 KB |
Output is correct |
63 |
Correct |
36 ms |
892 KB |
Output is correct |
64 |
Correct |
16 ms |
892 KB |
Output is correct |
65 |
Correct |
44 ms |
892 KB |
Output is correct |
66 |
Correct |
40 ms |
892 KB |
Output is correct |
67 |
Correct |
57 ms |
892 KB |
Output is correct |
68 |
Correct |
192 ms |
1012 KB |
Output is correct |
69 |
Correct |
50 ms |
1012 KB |
Output is correct |