#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;
const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;
template <class T> using V = vector<T>; // from yosupo
template <class T> using VV = V<V<T>>; // from yosupo
template <typename XPAX>
void ckma(XPAX &x, XPAX y) {
x = (x < y ? y : x);
}
template <typename XPAX>
void ckmi(XPAX &x, XPAX y) {
x = (x > y ? y : x);
}
int n;
int A, B;
int a[N];
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
void solve() {
cin >> n >> A >> B;
forn(i, n)cin >> a[i];
bool dp[n + 1][1000][n + 1];
memset(dp, false, sizeof(dp));
dp[0][0][0] = 1;
for(int i = 0;i < n;++i) {
for(int parti = 0;parti <= i;++parti) {
for(int now = 0;now <= 1000;++now) {
int tot = 0;
for(int j = i;j < n;++j) {
tot += a[j];
if((tot | now) < 1000 && dp[i][now][parti])dp[j + 1][tot | now][parti + 1] = 1;
}
}
}
}
int ans = INF;
for(int x = 0;x <= 1000;++x) {
for(int parti = A;parti <= B;++parti) {
if(dp[n][x][parti])ckmi(ans, x);
}
}
cout << ans << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
//cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
716 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
3 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
636 KB |
Output is correct |
21 |
Correct |
3 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
716 KB |
Output is correct |
23 |
Correct |
3 ms |
716 KB |
Output is correct |
24 |
Correct |
3 ms |
716 KB |
Output is correct |
25 |
Correct |
3 ms |
716 KB |
Output is correct |
26 |
Correct |
3 ms |
716 KB |
Output is correct |
27 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
716 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
3 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
588 KB |
Output is correct |
21 |
Correct |
3 ms |
716 KB |
Output is correct |
22 |
Correct |
3 ms |
716 KB |
Output is correct |
23 |
Correct |
3 ms |
716 KB |
Output is correct |
24 |
Correct |
3 ms |
748 KB |
Output is correct |
25 |
Correct |
5 ms |
716 KB |
Output is correct |
26 |
Correct |
3 ms |
716 KB |
Output is correct |
27 |
Correct |
4 ms |
716 KB |
Output is correct |
28 |
Correct |
5 ms |
972 KB |
Output is correct |
29 |
Correct |
16 ms |
1800 KB |
Output is correct |
30 |
Correct |
21 ms |
1996 KB |
Output is correct |
31 |
Correct |
36 ms |
2884 KB |
Output is correct |
32 |
Correct |
36 ms |
2764 KB |
Output is correct |
33 |
Correct |
35 ms |
2844 KB |
Output is correct |
34 |
Correct |
39 ms |
2764 KB |
Output is correct |
35 |
Correct |
34 ms |
2764 KB |
Output is correct |
36 |
Correct |
33 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
748 KB |
Output is correct |
9 |
Correct |
4 ms |
716 KB |
Output is correct |
10 |
Correct |
5 ms |
748 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
972 KB |
Output is correct |
16 |
Correct |
16 ms |
1800 KB |
Output is correct |
17 |
Correct |
20 ms |
2124 KB |
Output is correct |
18 |
Correct |
39 ms |
2764 KB |
Output is correct |
19 |
Correct |
35 ms |
2860 KB |
Output is correct |
20 |
Correct |
37 ms |
2836 KB |
Output is correct |
21 |
Correct |
35 ms |
2764 KB |
Output is correct |
22 |
Correct |
41 ms |
2844 KB |
Output is correct |
23 |
Correct |
34 ms |
2764 KB |
Output is correct |
24 |
Correct |
37 ms |
2960 KB |
Output is correct |
25 |
Correct |
82 ms |
4560 KB |
Output is correct |
26 |
Correct |
133 ms |
6400 KB |
Output is correct |
27 |
Correct |
213 ms |
8580 KB |
Output is correct |
28 |
Correct |
280 ms |
10280 KB |
Output is correct |
29 |
Correct |
302 ms |
10292 KB |
Output is correct |
30 |
Incorrect |
295 ms |
10280 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
716 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
3 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
588 KB |
Output is correct |
21 |
Correct |
3 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
716 KB |
Output is correct |
23 |
Correct |
3 ms |
716 KB |
Output is correct |
24 |
Correct |
5 ms |
716 KB |
Output is correct |
25 |
Correct |
3 ms |
716 KB |
Output is correct |
26 |
Correct |
3 ms |
716 KB |
Output is correct |
27 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
5 ms |
716 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
3 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |