/// In The Name Of God
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ioi exit(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = (int)2000 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
int n, A, B;
int a[N];
ll ans = linf;
unordered_map <ll, bool> dp[N][N];
void rec(int v = 1, int done = 0, ll cost = 0) {
if (done > B) return;
if (dp[v][done].count(cost)) return;
dp[v][done][cost] = 1;
if (v > n) {
if (A <= done && done <= B) {
ans = min(ans, cost);
}
return;
}
ll sum = 0;
for (int i = v; i <= n; i++) {
sum += a[i];
rec(i + 1, done + 1, cost | sum);
}
}
int main() {
#ifdef IOI2018
freopen ("in.txt", "r", stdin);
#endif
Kazakhstan
cin >> n >> A >> B;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
rec();
cout << ans;
ioi
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
221048 KB |
Output is correct |
2 |
Correct |
206 ms |
221280 KB |
Output is correct |
3 |
Correct |
212 ms |
221280 KB |
Output is correct |
4 |
Correct |
247 ms |
221280 KB |
Output is correct |
5 |
Correct |
203 ms |
221280 KB |
Output is correct |
6 |
Correct |
209 ms |
221356 KB |
Output is correct |
7 |
Correct |
204 ms |
221356 KB |
Output is correct |
8 |
Correct |
204 ms |
221356 KB |
Output is correct |
9 |
Correct |
205 ms |
221368 KB |
Output is correct |
10 |
Correct |
214 ms |
221368 KB |
Output is correct |
11 |
Correct |
201 ms |
221368 KB |
Output is correct |
12 |
Correct |
203 ms |
221368 KB |
Output is correct |
13 |
Correct |
197 ms |
221368 KB |
Output is correct |
14 |
Correct |
199 ms |
221368 KB |
Output is correct |
15 |
Correct |
202 ms |
221368 KB |
Output is correct |
16 |
Correct |
198 ms |
221536 KB |
Output is correct |
17 |
Correct |
195 ms |
221536 KB |
Output is correct |
18 |
Correct |
201 ms |
221536 KB |
Output is correct |
19 |
Correct |
197 ms |
221536 KB |
Output is correct |
20 |
Correct |
206 ms |
221536 KB |
Output is correct |
21 |
Correct |
201 ms |
221536 KB |
Output is correct |
22 |
Correct |
199 ms |
221536 KB |
Output is correct |
23 |
Correct |
204 ms |
221536 KB |
Output is correct |
24 |
Correct |
210 ms |
221536 KB |
Output is correct |
25 |
Correct |
210 ms |
221536 KB |
Output is correct |
26 |
Correct |
206 ms |
221536 KB |
Output is correct |
27 |
Correct |
209 ms |
221536 KB |
Output is correct |
28 |
Correct |
217 ms |
221536 KB |
Output is correct |
29 |
Correct |
209 ms |
221536 KB |
Output is correct |
30 |
Correct |
204 ms |
221536 KB |
Output is correct |
31 |
Correct |
221 ms |
221536 KB |
Output is correct |
32 |
Correct |
203 ms |
221536 KB |
Output is correct |
33 |
Correct |
204 ms |
221536 KB |
Output is correct |
34 |
Correct |
203 ms |
221536 KB |
Output is correct |
35 |
Correct |
212 ms |
221536 KB |
Output is correct |
36 |
Correct |
218 ms |
221536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
221536 KB |
Output is correct |
2 |
Correct |
203 ms |
221536 KB |
Output is correct |
3 |
Correct |
202 ms |
221536 KB |
Output is correct |
4 |
Correct |
203 ms |
221536 KB |
Output is correct |
5 |
Correct |
203 ms |
221536 KB |
Output is correct |
6 |
Correct |
211 ms |
221536 KB |
Output is correct |
7 |
Correct |
201 ms |
221536 KB |
Output is correct |
8 |
Correct |
204 ms |
221536 KB |
Output is correct |
9 |
Correct |
200 ms |
221536 KB |
Output is correct |
10 |
Correct |
204 ms |
221536 KB |
Output is correct |
11 |
Correct |
206 ms |
221536 KB |
Output is correct |
12 |
Correct |
212 ms |
221536 KB |
Output is correct |
13 |
Correct |
213 ms |
221536 KB |
Output is correct |
14 |
Correct |
202 ms |
221536 KB |
Output is correct |
15 |
Correct |
193 ms |
221536 KB |
Output is correct |
16 |
Correct |
203 ms |
221536 KB |
Output is correct |
17 |
Correct |
192 ms |
221536 KB |
Output is correct |
18 |
Correct |
203 ms |
221536 KB |
Output is correct |
19 |
Correct |
203 ms |
221536 KB |
Output is correct |
20 |
Correct |
198 ms |
221536 KB |
Output is correct |
21 |
Correct |
207 ms |
221536 KB |
Output is correct |
22 |
Correct |
193 ms |
221536 KB |
Output is correct |
23 |
Correct |
201 ms |
221536 KB |
Output is correct |
24 |
Correct |
202 ms |
221536 KB |
Output is correct |
25 |
Correct |
192 ms |
221536 KB |
Output is correct |
26 |
Correct |
203 ms |
221536 KB |
Output is correct |
27 |
Correct |
226 ms |
221620 KB |
Output is correct |
28 |
Correct |
199 ms |
221620 KB |
Output is correct |
29 |
Correct |
199 ms |
221620 KB |
Output is correct |
30 |
Correct |
200 ms |
221824 KB |
Output is correct |
31 |
Correct |
235 ms |
222408 KB |
Output is correct |
32 |
Correct |
208 ms |
222408 KB |
Output is correct |
33 |
Correct |
204 ms |
222408 KB |
Output is correct |
34 |
Correct |
223 ms |
222408 KB |
Output is correct |
35 |
Correct |
208 ms |
222408 KB |
Output is correct |
36 |
Correct |
201 ms |
222408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
222408 KB |
Output is correct |
2 |
Correct |
201 ms |
222408 KB |
Output is correct |
3 |
Correct |
198 ms |
222408 KB |
Output is correct |
4 |
Correct |
195 ms |
222408 KB |
Output is correct |
5 |
Correct |
195 ms |
222408 KB |
Output is correct |
6 |
Correct |
195 ms |
222408 KB |
Output is correct |
7 |
Correct |
196 ms |
222408 KB |
Output is correct |
8 |
Correct |
215 ms |
222408 KB |
Output is correct |
9 |
Correct |
210 ms |
222408 KB |
Output is correct |
10 |
Correct |
210 ms |
222408 KB |
Output is correct |
11 |
Correct |
199 ms |
222408 KB |
Output is correct |
12 |
Correct |
202 ms |
222408 KB |
Output is correct |
13 |
Correct |
194 ms |
222408 KB |
Output is correct |
14 |
Correct |
209 ms |
222408 KB |
Output is correct |
15 |
Correct |
200 ms |
222408 KB |
Output is correct |
16 |
Correct |
200 ms |
222408 KB |
Output is correct |
17 |
Correct |
199 ms |
222408 KB |
Output is correct |
18 |
Correct |
221 ms |
222432 KB |
Output is correct |
19 |
Correct |
209 ms |
222432 KB |
Output is correct |
20 |
Correct |
197 ms |
222432 KB |
Output is correct |
21 |
Correct |
227 ms |
222432 KB |
Output is correct |
22 |
Correct |
211 ms |
222432 KB |
Output is correct |
23 |
Correct |
213 ms |
222432 KB |
Output is correct |
24 |
Correct |
218 ms |
222604 KB |
Output is correct |
25 |
Correct |
233 ms |
222636 KB |
Output is correct |
26 |
Correct |
326 ms |
225516 KB |
Output is correct |
27 |
Correct |
486 ms |
228876 KB |
Output is correct |
28 |
Correct |
618 ms |
231584 KB |
Output is correct |
29 |
Correct |
441 ms |
231584 KB |
Output is correct |
30 |
Correct |
197 ms |
231584 KB |
Output is correct |
31 |
Correct |
669 ms |
232388 KB |
Output is correct |
32 |
Correct |
714 ms |
233132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
233132 KB |
Output is correct |
2 |
Correct |
193 ms |
233132 KB |
Output is correct |
3 |
Correct |
203 ms |
233132 KB |
Output is correct |
4 |
Correct |
202 ms |
233132 KB |
Output is correct |
5 |
Correct |
204 ms |
233132 KB |
Output is correct |
6 |
Correct |
195 ms |
233132 KB |
Output is correct |
7 |
Correct |
207 ms |
233132 KB |
Output is correct |
8 |
Correct |
196 ms |
233132 KB |
Output is correct |
9 |
Correct |
202 ms |
233132 KB |
Output is correct |
10 |
Correct |
195 ms |
233132 KB |
Output is correct |
11 |
Correct |
198 ms |
233132 KB |
Output is correct |
12 |
Correct |
198 ms |
233132 KB |
Output is correct |
13 |
Correct |
194 ms |
233132 KB |
Output is correct |
14 |
Correct |
196 ms |
233132 KB |
Output is correct |
15 |
Correct |
196 ms |
233132 KB |
Output is correct |
16 |
Correct |
192 ms |
233132 KB |
Output is correct |
17 |
Correct |
192 ms |
233132 KB |
Output is correct |
18 |
Correct |
194 ms |
233132 KB |
Output is correct |
19 |
Correct |
192 ms |
233132 KB |
Output is correct |
20 |
Correct |
209 ms |
233132 KB |
Output is correct |
21 |
Correct |
192 ms |
233132 KB |
Output is correct |
22 |
Correct |
193 ms |
233132 KB |
Output is correct |
23 |
Correct |
192 ms |
233132 KB |
Output is correct |
24 |
Correct |
194 ms |
233132 KB |
Output is correct |
25 |
Correct |
194 ms |
233132 KB |
Output is correct |
26 |
Correct |
194 ms |
233132 KB |
Output is correct |
27 |
Correct |
196 ms |
233132 KB |
Output is correct |
28 |
Correct |
192 ms |
233132 KB |
Output is correct |
29 |
Correct |
198 ms |
233132 KB |
Output is correct |
30 |
Correct |
195 ms |
233132 KB |
Output is correct |
31 |
Correct |
193 ms |
233132 KB |
Output is correct |
32 |
Correct |
195 ms |
233132 KB |
Output is correct |
33 |
Correct |
191 ms |
233132 KB |
Output is correct |
34 |
Correct |
193 ms |
233132 KB |
Output is correct |
35 |
Correct |
196 ms |
233132 KB |
Output is correct |
36 |
Correct |
191 ms |
233132 KB |
Output is correct |
37 |
Correct |
193 ms |
233132 KB |
Output is correct |
38 |
Correct |
193 ms |
233132 KB |
Output is correct |
39 |
Correct |
193 ms |
233132 KB |
Output is correct |
40 |
Correct |
202 ms |
233132 KB |
Output is correct |
41 |
Correct |
237 ms |
233132 KB |
Output is correct |
42 |
Correct |
216 ms |
233132 KB |
Output is correct |
43 |
Correct |
202 ms |
233132 KB |
Output is correct |
44 |
Correct |
208 ms |
233132 KB |
Output is correct |
45 |
Correct |
208 ms |
233132 KB |
Output is correct |
46 |
Correct |
219 ms |
233132 KB |
Output is correct |
47 |
Correct |
233 ms |
233132 KB |
Output is correct |
48 |
Correct |
233 ms |
233132 KB |
Output is correct |
49 |
Correct |
323 ms |
233132 KB |
Output is correct |
50 |
Correct |
484 ms |
233132 KB |
Output is correct |
51 |
Correct |
581 ms |
233132 KB |
Output is correct |
52 |
Correct |
448 ms |
233132 KB |
Output is correct |
53 |
Correct |
193 ms |
233132 KB |
Output is correct |
54 |
Correct |
694 ms |
233132 KB |
Output is correct |
55 |
Correct |
754 ms |
233132 KB |
Output is correct |
56 |
Execution timed out |
1091 ms |
249196 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
249196 KB |
Output is correct |
2 |
Correct |
192 ms |
249196 KB |
Output is correct |
3 |
Correct |
199 ms |
249196 KB |
Output is correct |
4 |
Correct |
210 ms |
249196 KB |
Output is correct |
5 |
Correct |
199 ms |
249196 KB |
Output is correct |
6 |
Correct |
198 ms |
249196 KB |
Output is correct |
7 |
Correct |
198 ms |
249196 KB |
Output is correct |
8 |
Correct |
203 ms |
249196 KB |
Output is correct |
9 |
Correct |
197 ms |
249196 KB |
Output is correct |
10 |
Correct |
200 ms |
249196 KB |
Output is correct |
11 |
Correct |
195 ms |
249196 KB |
Output is correct |
12 |
Correct |
197 ms |
249196 KB |
Output is correct |
13 |
Correct |
206 ms |
249196 KB |
Output is correct |
14 |
Correct |
208 ms |
249196 KB |
Output is correct |
15 |
Correct |
213 ms |
249196 KB |
Output is correct |
16 |
Correct |
223 ms |
249196 KB |
Output is correct |
17 |
Correct |
218 ms |
249196 KB |
Output is correct |
18 |
Correct |
208 ms |
249196 KB |
Output is correct |
19 |
Correct |
195 ms |
249196 KB |
Output is correct |
20 |
Correct |
195 ms |
249196 KB |
Output is correct |
21 |
Correct |
200 ms |
249196 KB |
Output is correct |
22 |
Correct |
197 ms |
249196 KB |
Output is correct |
23 |
Correct |
201 ms |
249196 KB |
Output is correct |
24 |
Correct |
202 ms |
249196 KB |
Output is correct |
25 |
Correct |
196 ms |
249196 KB |
Output is correct |
26 |
Correct |
196 ms |
249196 KB |
Output is correct |
27 |
Correct |
208 ms |
249196 KB |
Output is correct |
28 |
Correct |
227 ms |
249196 KB |
Output is correct |
29 |
Correct |
202 ms |
249196 KB |
Output is correct |
30 |
Correct |
197 ms |
249196 KB |
Output is correct |
31 |
Correct |
214 ms |
249196 KB |
Output is correct |
32 |
Correct |
238 ms |
249196 KB |
Output is correct |
33 |
Correct |
205 ms |
249196 KB |
Output is correct |
34 |
Correct |
238 ms |
249196 KB |
Output is correct |
35 |
Correct |
244 ms |
249196 KB |
Output is correct |
36 |
Correct |
332 ms |
249196 KB |
Output is correct |
37 |
Correct |
483 ms |
249196 KB |
Output is correct |
38 |
Correct |
613 ms |
249196 KB |
Output is correct |
39 |
Correct |
471 ms |
249196 KB |
Output is correct |
40 |
Correct |
209 ms |
249196 KB |
Output is correct |
41 |
Correct |
738 ms |
249196 KB |
Output is correct |
42 |
Correct |
844 ms |
249196 KB |
Output is correct |
43 |
Execution timed out |
1092 ms |
249196 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |