#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
unordered_map<int, unordered_map<int, int> > dp[101];
int a[110], p[110], n;
int f(int i, int k, int o) {
if(k > i) return 1e9;
if(k == 1) return p[i] | o;
if(dp[i].count(k)) if(dp[i][k].count(o)) return dp[i][k][o];
int &ret = dp[i][k][o];
int sum = a[i];
ret = 1e9;
for(int j = i - 1; j >= 1; j--) {
ret = min(ret, f(j, k - 1, sum | o) | sum | o);
sum += a[j];
}
return ret;
}
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
int n, l, r;
cin >> n >> l >> r;
for(int i = 1; i <= n; i++) {
cin >> a[i]; p[i] = p[i - 1] + a[i];
}
int ans = 1e9;
for(int i = l; i <= r; i++) {
ans = min(ans, f(n, i, 0));
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
1 ms |
484 KB |
Output is correct |
4 |
Correct |
1 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
532 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
552 KB |
Output is correct |
8 |
Correct |
1 ms |
572 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
616 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
620 KB |
Output is correct |
16 |
Correct |
1 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
1 ms |
620 KB |
Output is correct |
19 |
Correct |
1 ms |
620 KB |
Output is correct |
20 |
Correct |
1 ms |
620 KB |
Output is correct |
21 |
Correct |
2 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
1 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
624 KB |
Output is correct |
27 |
Incorrect |
1 ms |
624 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
624 KB |
Output is correct |
2 |
Correct |
2 ms |
624 KB |
Output is correct |
3 |
Correct |
1 ms |
624 KB |
Output is correct |
4 |
Correct |
1 ms |
624 KB |
Output is correct |
5 |
Correct |
1 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 |
2 ms |
744 KB |
Output is correct |
11 |
Correct |
2 ms |
744 KB |
Output is correct |
12 |
Correct |
2 ms |
744 KB |
Output is correct |
13 |
Correct |
2 ms |
744 KB |
Output is correct |
14 |
Correct |
1 ms |
744 KB |
Output is correct |
15 |
Correct |
2 ms |
744 KB |
Output is correct |
16 |
Correct |
1 ms |
744 KB |
Output is correct |
17 |
Correct |
2 ms |
744 KB |
Output is correct |
18 |
Correct |
2 ms |
744 KB |
Output is correct |
19 |
Correct |
2 ms |
744 KB |
Output is correct |
20 |
Correct |
1 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
744 KB |
Output is correct |
22 |
Correct |
2 ms |
744 KB |
Output is correct |
23 |
Correct |
2 ms |
744 KB |
Output is correct |
24 |
Correct |
1 ms |
744 KB |
Output is correct |
25 |
Correct |
2 ms |
744 KB |
Output is correct |
26 |
Correct |
3 ms |
744 KB |
Output is correct |
27 |
Correct |
2 ms |
744 KB |
Output is correct |
28 |
Correct |
3 ms |
744 KB |
Output is correct |
29 |
Correct |
2 ms |
744 KB |
Output is correct |
30 |
Correct |
17 ms |
1004 KB |
Output is correct |
31 |
Correct |
57 ms |
1804 KB |
Output is correct |
32 |
Correct |
60 ms |
1804 KB |
Output is correct |
33 |
Correct |
1 ms |
1804 KB |
Output is correct |
34 |
Correct |
35 ms |
1804 KB |
Output is correct |
35 |
Correct |
45 ms |
1804 KB |
Output is correct |
36 |
Correct |
18 ms |
1804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1804 KB |
Output is correct |
2 |
Correct |
1 ms |
1804 KB |
Output is correct |
3 |
Correct |
1 ms |
1804 KB |
Output is correct |
4 |
Correct |
2 ms |
1804 KB |
Output is correct |
5 |
Correct |
2 ms |
1804 KB |
Output is correct |
6 |
Correct |
2 ms |
1804 KB |
Output is correct |
7 |
Correct |
1 ms |
1804 KB |
Output is correct |
8 |
Correct |
2 ms |
1804 KB |
Output is correct |
9 |
Correct |
2 ms |
1804 KB |
Output is correct |
10 |
Correct |
2 ms |
1804 KB |
Output is correct |
11 |
Correct |
1 ms |
1804 KB |
Output is correct |
12 |
Correct |
1 ms |
1804 KB |
Output is correct |
13 |
Correct |
2 ms |
1804 KB |
Output is correct |
14 |
Correct |
2 ms |
1804 KB |
Output is correct |
15 |
Correct |
3 ms |
1804 KB |
Output is correct |
16 |
Correct |
2 ms |
1804 KB |
Output is correct |
17 |
Correct |
18 ms |
1804 KB |
Output is correct |
18 |
Correct |
60 ms |
1816 KB |
Output is correct |
19 |
Correct |
38 ms |
1816 KB |
Output is correct |
20 |
Correct |
1 ms |
1816 KB |
Output is correct |
21 |
Correct |
43 ms |
1816 KB |
Output is correct |
22 |
Correct |
50 ms |
1816 KB |
Output is correct |
23 |
Correct |
17 ms |
1816 KB |
Output is correct |
24 |
Correct |
47 ms |
1816 KB |
Output is correct |
25 |
Correct |
63 ms |
1816 KB |
Output is correct |
26 |
Correct |
392 ms |
5776 KB |
Output is correct |
27 |
Execution timed out |
1056 ms |
12264 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
12264 KB |
Output is correct |
2 |
Correct |
2 ms |
12264 KB |
Output is correct |
3 |
Correct |
1 ms |
12264 KB |
Output is correct |
4 |
Correct |
2 ms |
12264 KB |
Output is correct |
5 |
Correct |
1 ms |
12264 KB |
Output is correct |
6 |
Correct |
2 ms |
12264 KB |
Output is correct |
7 |
Correct |
1 ms |
12264 KB |
Output is correct |
8 |
Correct |
1 ms |
12264 KB |
Output is correct |
9 |
Correct |
2 ms |
12264 KB |
Output is correct |
10 |
Correct |
2 ms |
12264 KB |
Output is correct |
11 |
Correct |
1 ms |
12264 KB |
Output is correct |
12 |
Correct |
2 ms |
12264 KB |
Output is correct |
13 |
Correct |
2 ms |
12264 KB |
Output is correct |
14 |
Correct |
1 ms |
12264 KB |
Output is correct |
15 |
Correct |
1 ms |
12264 KB |
Output is correct |
16 |
Correct |
2 ms |
12264 KB |
Output is correct |
17 |
Correct |
2 ms |
12264 KB |
Output is correct |
18 |
Correct |
2 ms |
12264 KB |
Output is correct |
19 |
Correct |
2 ms |
12264 KB |
Output is correct |
20 |
Correct |
1 ms |
12264 KB |
Output is correct |
21 |
Correct |
2 ms |
12264 KB |
Output is correct |
22 |
Correct |
2 ms |
12264 KB |
Output is correct |
23 |
Correct |
2 ms |
12264 KB |
Output is correct |
24 |
Correct |
2 ms |
12264 KB |
Output is correct |
25 |
Correct |
2 ms |
12264 KB |
Output is correct |
26 |
Correct |
2 ms |
12264 KB |
Output is correct |
27 |
Incorrect |
2 ms |
12264 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12264 KB |
Output is correct |
2 |
Correct |
1 ms |
12264 KB |
Output is correct |
3 |
Correct |
1 ms |
12264 KB |
Output is correct |
4 |
Correct |
1 ms |
12264 KB |
Output is correct |
5 |
Correct |
1 ms |
12264 KB |
Output is correct |
6 |
Correct |
2 ms |
12264 KB |
Output is correct |
7 |
Correct |
1 ms |
12264 KB |
Output is correct |
8 |
Correct |
2 ms |
12264 KB |
Output is correct |
9 |
Correct |
2 ms |
12264 KB |
Output is correct |
10 |
Correct |
2 ms |
12264 KB |
Output is correct |
11 |
Correct |
1 ms |
12264 KB |
Output is correct |
12 |
Correct |
1 ms |
12264 KB |
Output is correct |
13 |
Correct |
3 ms |
12264 KB |
Output is correct |
14 |
Incorrect |
2 ms |
12264 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |