#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e15;
const int nax = 2000;
ll a, b, n;
ll y[nax+5];
ll p[nax+5];
ll dp[nax+5][nax+5];
bool ok (int x) {
return a <= x && x <= b;
}
ll f(int idx, int grup) {
if(idx == n+1) return ok(grup) ? 0 : 1e5;
ll &res = dp[idx][grup];
if(~res) return res;
res = INF;
for(int i=idx; i<=n; i++) {
res = min(res, (p[i] - p[idx-1]) | f(i+1, grup+1));
}
//cerr << idx << " " << grup << " " << res << endl;
return res;
}
ll rec(int idx, ll sum, ll val, int grup) {
if(idx==n) return (a <= grup && grup <= b) ? (val | (sum + y[n])) : INF;
return min(rec(idx+1, sum+y[idx], val, grup), rec(idx+1, 0, val | (sum+y[idx]), grup+1));
}
ll solve1 () {
memset(dp, -1, sizeof (dp));
return f(1,0);
}
ll solve2(){
return rec(1, 0, 0, 1);
}
mt19937 mt(time(nullptr));
ll rand (ll x) {
unsigned long long m = mt();
return m % x;
}
int main() {
scanf("%lld %lld %lld", &n, &a, &b);
for(int i=1; i<=n; i++) {
scanf("%lld", &y[i]);
p[i] = y[i] + p[i-1];
}
solve1();
printf("%lld", f(1, 0));
}
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%lld %lld %lld", &n, &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%lld", &y[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31692 KB |
Output is correct |
2 |
Correct |
13 ms |
31692 KB |
Output is correct |
3 |
Correct |
13 ms |
31724 KB |
Output is correct |
4 |
Correct |
13 ms |
31692 KB |
Output is correct |
5 |
Correct |
13 ms |
31692 KB |
Output is correct |
6 |
Correct |
13 ms |
31692 KB |
Output is correct |
7 |
Correct |
13 ms |
31692 KB |
Output is correct |
8 |
Correct |
12 ms |
31660 KB |
Output is correct |
9 |
Correct |
13 ms |
31692 KB |
Output is correct |
10 |
Correct |
13 ms |
31752 KB |
Output is correct |
11 |
Correct |
13 ms |
31692 KB |
Output is correct |
12 |
Correct |
12 ms |
31700 KB |
Output is correct |
13 |
Correct |
14 ms |
31876 KB |
Output is correct |
14 |
Correct |
14 ms |
31692 KB |
Output is correct |
15 |
Correct |
13 ms |
31692 KB |
Output is correct |
16 |
Correct |
12 ms |
31652 KB |
Output is correct |
17 |
Correct |
12 ms |
31764 KB |
Output is correct |
18 |
Correct |
13 ms |
31676 KB |
Output is correct |
19 |
Correct |
13 ms |
31692 KB |
Output is correct |
20 |
Correct |
13 ms |
31680 KB |
Output is correct |
21 |
Incorrect |
12 ms |
31692 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31696 KB |
Output is correct |
2 |
Correct |
13 ms |
31692 KB |
Output is correct |
3 |
Correct |
12 ms |
31736 KB |
Output is correct |
4 |
Correct |
14 ms |
31700 KB |
Output is correct |
5 |
Correct |
14 ms |
31692 KB |
Output is correct |
6 |
Correct |
13 ms |
31692 KB |
Output is correct |
7 |
Correct |
13 ms |
31736 KB |
Output is correct |
8 |
Correct |
16 ms |
31820 KB |
Output is correct |
9 |
Correct |
15 ms |
31760 KB |
Output is correct |
10 |
Correct |
13 ms |
31672 KB |
Output is correct |
11 |
Correct |
14 ms |
31692 KB |
Output is correct |
12 |
Correct |
13 ms |
31692 KB |
Output is correct |
13 |
Correct |
13 ms |
31752 KB |
Output is correct |
14 |
Correct |
13 ms |
31728 KB |
Output is correct |
15 |
Correct |
13 ms |
31692 KB |
Output is correct |
16 |
Correct |
13 ms |
31684 KB |
Output is correct |
17 |
Correct |
13 ms |
31692 KB |
Output is correct |
18 |
Correct |
13 ms |
31692 KB |
Output is correct |
19 |
Correct |
12 ms |
31692 KB |
Output is correct |
20 |
Correct |
13 ms |
31728 KB |
Output is correct |
21 |
Incorrect |
13 ms |
31764 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31776 KB |
Output is correct |
2 |
Correct |
12 ms |
31692 KB |
Output is correct |
3 |
Correct |
13 ms |
31692 KB |
Output is correct |
4 |
Correct |
12 ms |
31692 KB |
Output is correct |
5 |
Correct |
12 ms |
31756 KB |
Output is correct |
6 |
Correct |
14 ms |
31692 KB |
Output is correct |
7 |
Correct |
14 ms |
31756 KB |
Output is correct |
8 |
Correct |
13 ms |
31680 KB |
Output is correct |
9 |
Correct |
13 ms |
31672 KB |
Output is correct |
10 |
Correct |
13 ms |
31692 KB |
Output is correct |
11 |
Correct |
13 ms |
31756 KB |
Output is correct |
12 |
Correct |
13 ms |
31692 KB |
Output is correct |
13 |
Correct |
13 ms |
31772 KB |
Output is correct |
14 |
Correct |
13 ms |
31684 KB |
Output is correct |
15 |
Correct |
13 ms |
31716 KB |
Output is correct |
16 |
Correct |
13 ms |
31692 KB |
Output is correct |
17 |
Correct |
13 ms |
31692 KB |
Output is correct |
18 |
Correct |
13 ms |
31692 KB |
Output is correct |
19 |
Correct |
13 ms |
31760 KB |
Output is correct |
20 |
Correct |
13 ms |
31652 KB |
Output is correct |
21 |
Correct |
14 ms |
31676 KB |
Output is correct |
22 |
Correct |
13 ms |
31768 KB |
Output is correct |
23 |
Correct |
14 ms |
31772 KB |
Output is correct |
24 |
Correct |
13 ms |
31692 KB |
Output is correct |
25 |
Correct |
13 ms |
31692 KB |
Output is correct |
26 |
Correct |
14 ms |
31692 KB |
Output is correct |
27 |
Correct |
16 ms |
31692 KB |
Output is correct |
28 |
Correct |
15 ms |
31692 KB |
Output is correct |
29 |
Correct |
17 ms |
31668 KB |
Output is correct |
30 |
Correct |
14 ms |
31768 KB |
Output is correct |
31 |
Correct |
13 ms |
31692 KB |
Output is correct |
32 |
Correct |
13 ms |
31768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31772 KB |
Output is correct |
2 |
Correct |
12 ms |
31692 KB |
Output is correct |
3 |
Correct |
14 ms |
31692 KB |
Output is correct |
4 |
Correct |
13 ms |
31692 KB |
Output is correct |
5 |
Correct |
13 ms |
31692 KB |
Output is correct |
6 |
Correct |
14 ms |
31692 KB |
Output is correct |
7 |
Correct |
13 ms |
31692 KB |
Output is correct |
8 |
Correct |
13 ms |
31692 KB |
Output is correct |
9 |
Correct |
14 ms |
31736 KB |
Output is correct |
10 |
Correct |
13 ms |
31692 KB |
Output is correct |
11 |
Correct |
13 ms |
31692 KB |
Output is correct |
12 |
Correct |
12 ms |
31692 KB |
Output is correct |
13 |
Correct |
12 ms |
31692 KB |
Output is correct |
14 |
Correct |
14 ms |
31744 KB |
Output is correct |
15 |
Correct |
13 ms |
31760 KB |
Output is correct |
16 |
Correct |
13 ms |
31684 KB |
Output is correct |
17 |
Correct |
13 ms |
31692 KB |
Output is correct |
18 |
Correct |
13 ms |
31692 KB |
Output is correct |
19 |
Correct |
12 ms |
31692 KB |
Output is correct |
20 |
Correct |
12 ms |
31716 KB |
Output is correct |
21 |
Incorrect |
18 ms |
31692 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31692 KB |
Output is correct |
2 |
Correct |
12 ms |
31692 KB |
Output is correct |
3 |
Correct |
12 ms |
31692 KB |
Output is correct |
4 |
Correct |
14 ms |
31716 KB |
Output is correct |
5 |
Correct |
15 ms |
31820 KB |
Output is correct |
6 |
Correct |
14 ms |
31692 KB |
Output is correct |
7 |
Correct |
13 ms |
31692 KB |
Output is correct |
8 |
Correct |
13 ms |
31692 KB |
Output is correct |
9 |
Correct |
13 ms |
31692 KB |
Output is correct |
10 |
Correct |
13 ms |
31692 KB |
Output is correct |
11 |
Correct |
13 ms |
31704 KB |
Output is correct |
12 |
Correct |
13 ms |
31692 KB |
Output is correct |
13 |
Correct |
13 ms |
31664 KB |
Output is correct |
14 |
Correct |
13 ms |
31760 KB |
Output is correct |
15 |
Incorrect |
13 ms |
31724 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |