#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2018;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
int N, A, B;
ll P[MAXN];
int dp[MAXN];
bitset<MAXN> msk[MAXN];
bool can (ll cur, int pos, ll s) {
return (s ^ (s & cur)) < (1ll << pos);
}
bool moo (ll cur, int pos) {
//try NOT to add pos.
//But at the same time, keep the leading bits.
//is it possible to do it in this amount?
if (A == 1) {
//need N^2, not N^3 / 32.
dp[0] = 0;
for (int i = 1; i <= N; i++) {
dp[i] = MAXN;
for (int j = 0; j < i; j++) {
ll s = P[i] - P[j];
//s, cur, pos are what matter.
//whatever s has and cur does not have.
//110101........ (cur)
// p
// c c c
//"c"s indicate the bits that can't be set
//note that c is also at the first dot.
if (can(cur, pos, s)) {
dp[i] = min(dp[i], dp[j] + 1);
}
}
}
return dp[N] <= B;
} else {
msk[0][0] = 1;
for (int i = 1; i <= N; i++) {
msk[i].reset();
for (int j = 0; j < i; j++) {
ll s = P[i] - P[j];
if (can(cur, pos, s)) {
msk[i] |= (msk[j] << 1);
}
}
}
for (int i = A; i <= B; i++) {
if (msk[N][i]) {
return true;
}
}
return false;
}
}
int main() {
scanf("%d %d %d", &N, &A, &B);
for (int i = 1; i <= N; i++) {
scanf("%lld", &P[i]);
P[i] += P[i - 1];
}
ll ans = 0;
for (int i = 42; i >= 0; i--) {
if (!moo(ans, i)) {
ans ^= (1ll << i);
}
}
printf("%lld\n", ans);
}
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:72:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &N, &A, &B);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &P[i]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
3 ms |
656 KB |
Output is correct |
5 |
Correct |
2 ms |
656 KB |
Output is correct |
6 |
Correct |
3 ms |
680 KB |
Output is correct |
7 |
Correct |
4 ms |
684 KB |
Output is correct |
8 |
Correct |
4 ms |
688 KB |
Output is correct |
9 |
Correct |
27 ms |
692 KB |
Output is correct |
10 |
Correct |
2 ms |
696 KB |
Output is correct |
11 |
Correct |
2 ms |
700 KB |
Output is correct |
12 |
Correct |
3 ms |
704 KB |
Output is correct |
13 |
Correct |
3 ms |
704 KB |
Output is correct |
14 |
Correct |
3 ms |
712 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
4 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
3 ms |
752 KB |
Output is correct |
20 |
Correct |
3 ms |
756 KB |
Output is correct |
21 |
Correct |
4 ms |
760 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
3 ms |
768 KB |
Output is correct |
24 |
Correct |
4 ms |
776 KB |
Output is correct |
25 |
Correct |
3 ms |
776 KB |
Output is correct |
26 |
Correct |
2 ms |
780 KB |
Output is correct |
27 |
Correct |
2 ms |
784 KB |
Output is correct |
28 |
Correct |
2 ms |
788 KB |
Output is correct |
29 |
Correct |
2 ms |
792 KB |
Output is correct |
30 |
Correct |
2 ms |
796 KB |
Output is correct |
31 |
Correct |
2 ms |
916 KB |
Output is correct |
32 |
Correct |
3 ms |
916 KB |
Output is correct |
33 |
Correct |
3 ms |
916 KB |
Output is correct |
34 |
Correct |
2 ms |
916 KB |
Output is correct |
35 |
Correct |
2 ms |
916 KB |
Output is correct |
36 |
Correct |
2 ms |
916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
916 KB |
Output is correct |
2 |
Correct |
3 ms |
916 KB |
Output is correct |
3 |
Correct |
2 ms |
944 KB |
Output is correct |
4 |
Correct |
3 ms |
944 KB |
Output is correct |
5 |
Correct |
3 ms |
944 KB |
Output is correct |
6 |
Correct |
2 ms |
944 KB |
Output is correct |
7 |
Correct |
3 ms |
944 KB |
Output is correct |
8 |
Correct |
2 ms |
944 KB |
Output is correct |
9 |
Correct |
2 ms |
944 KB |
Output is correct |
10 |
Correct |
4 ms |
944 KB |
Output is correct |
11 |
Correct |
2 ms |
944 KB |
Output is correct |
12 |
Correct |
3 ms |
944 KB |
Output is correct |
13 |
Correct |
3 ms |
944 KB |
Output is correct |
14 |
Correct |
3 ms |
944 KB |
Output is correct |
15 |
Correct |
3 ms |
944 KB |
Output is correct |
16 |
Correct |
3 ms |
944 KB |
Output is correct |
17 |
Correct |
2 ms |
944 KB |
Output is correct |
18 |
Correct |
3 ms |
1004 KB |
Output is correct |
19 |
Correct |
3 ms |
1004 KB |
Output is correct |
20 |
Correct |
4 ms |
1004 KB |
Output is correct |
21 |
Correct |
4 ms |
1004 KB |
Output is correct |
22 |
Correct |
3 ms |
1004 KB |
Output is correct |
23 |
Correct |
3 ms |
1004 KB |
Output is correct |
24 |
Correct |
4 ms |
1120 KB |
Output is correct |
25 |
Correct |
3 ms |
1120 KB |
Output is correct |
26 |
Correct |
3 ms |
1120 KB |
Output is correct |
27 |
Correct |
3 ms |
1120 KB |
Output is correct |
28 |
Correct |
3 ms |
1140 KB |
Output is correct |
29 |
Correct |
3 ms |
1140 KB |
Output is correct |
30 |
Correct |
3 ms |
1144 KB |
Output is correct |
31 |
Correct |
3 ms |
1144 KB |
Output is correct |
32 |
Correct |
3 ms |
1144 KB |
Output is correct |
33 |
Correct |
2 ms |
1144 KB |
Output is correct |
34 |
Correct |
3 ms |
1144 KB |
Output is correct |
35 |
Correct |
3 ms |
1144 KB |
Output is correct |
36 |
Correct |
3 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1188 KB |
Output is correct |
2 |
Correct |
2 ms |
1196 KB |
Output is correct |
3 |
Correct |
2 ms |
1200 KB |
Output is correct |
4 |
Correct |
3 ms |
1204 KB |
Output is correct |
5 |
Correct |
3 ms |
1208 KB |
Output is correct |
6 |
Correct |
3 ms |
1324 KB |
Output is correct |
7 |
Correct |
3 ms |
1324 KB |
Output is correct |
8 |
Correct |
3 ms |
1324 KB |
Output is correct |
9 |
Correct |
2 ms |
1324 KB |
Output is correct |
10 |
Correct |
3 ms |
1324 KB |
Output is correct |
11 |
Correct |
2 ms |
1324 KB |
Output is correct |
12 |
Correct |
3 ms |
1324 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
14 |
Correct |
3 ms |
1360 KB |
Output is correct |
15 |
Correct |
2 ms |
1408 KB |
Output is correct |
16 |
Correct |
3 ms |
1408 KB |
Output is correct |
17 |
Correct |
3 ms |
1408 KB |
Output is correct |
18 |
Correct |
4 ms |
1408 KB |
Output is correct |
19 |
Correct |
4 ms |
1408 KB |
Output is correct |
20 |
Correct |
3 ms |
1408 KB |
Output is correct |
21 |
Correct |
3 ms |
1408 KB |
Output is correct |
22 |
Correct |
4 ms |
1408 KB |
Output is correct |
23 |
Correct |
2 ms |
1408 KB |
Output is correct |
24 |
Correct |
3 ms |
1408 KB |
Output is correct |
25 |
Correct |
3 ms |
1408 KB |
Output is correct |
26 |
Correct |
4 ms |
1408 KB |
Output is correct |
27 |
Correct |
3 ms |
1408 KB |
Output is correct |
28 |
Correct |
4 ms |
1408 KB |
Output is correct |
29 |
Correct |
4 ms |
1408 KB |
Output is correct |
30 |
Correct |
3 ms |
1408 KB |
Output is correct |
31 |
Correct |
4 ms |
1440 KB |
Output is correct |
32 |
Correct |
3 ms |
1440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1440 KB |
Output is correct |
2 |
Correct |
2 ms |
1440 KB |
Output is correct |
3 |
Correct |
3 ms |
1440 KB |
Output is correct |
4 |
Correct |
3 ms |
1440 KB |
Output is correct |
5 |
Correct |
3 ms |
1440 KB |
Output is correct |
6 |
Correct |
3 ms |
1440 KB |
Output is correct |
7 |
Correct |
4 ms |
1440 KB |
Output is correct |
8 |
Correct |
4 ms |
1440 KB |
Output is correct |
9 |
Correct |
3 ms |
1440 KB |
Output is correct |
10 |
Correct |
3 ms |
1440 KB |
Output is correct |
11 |
Correct |
3 ms |
1440 KB |
Output is correct |
12 |
Correct |
3 ms |
1520 KB |
Output is correct |
13 |
Correct |
4 ms |
1520 KB |
Output is correct |
14 |
Correct |
2 ms |
1520 KB |
Output is correct |
15 |
Correct |
2 ms |
1520 KB |
Output is correct |
16 |
Correct |
4 ms |
1520 KB |
Output is correct |
17 |
Correct |
3 ms |
1520 KB |
Output is correct |
18 |
Correct |
3 ms |
1520 KB |
Output is correct |
19 |
Correct |
3 ms |
1544 KB |
Output is correct |
20 |
Correct |
2 ms |
1544 KB |
Output is correct |
21 |
Correct |
3 ms |
1544 KB |
Output is correct |
22 |
Correct |
3 ms |
1544 KB |
Output is correct |
23 |
Correct |
2 ms |
1544 KB |
Output is correct |
24 |
Correct |
3 ms |
1544 KB |
Output is correct |
25 |
Correct |
3 ms |
1544 KB |
Output is correct |
26 |
Correct |
3 ms |
1544 KB |
Output is correct |
27 |
Correct |
3 ms |
1544 KB |
Output is correct |
28 |
Correct |
2 ms |
1544 KB |
Output is correct |
29 |
Correct |
3 ms |
1544 KB |
Output is correct |
30 |
Correct |
3 ms |
1544 KB |
Output is correct |
31 |
Correct |
3 ms |
1544 KB |
Output is correct |
32 |
Correct |
3 ms |
1544 KB |
Output is correct |
33 |
Correct |
3 ms |
1544 KB |
Output is correct |
34 |
Correct |
3 ms |
1544 KB |
Output is correct |
35 |
Correct |
3 ms |
1544 KB |
Output is correct |
36 |
Correct |
3 ms |
1544 KB |
Output is correct |
37 |
Correct |
3 ms |
1544 KB |
Output is correct |
38 |
Correct |
3 ms |
1544 KB |
Output is correct |
39 |
Correct |
2 ms |
1544 KB |
Output is correct |
40 |
Correct |
2 ms |
1544 KB |
Output is correct |
41 |
Correct |
2 ms |
1544 KB |
Output is correct |
42 |
Correct |
3 ms |
1544 KB |
Output is correct |
43 |
Correct |
3 ms |
1544 KB |
Output is correct |
44 |
Correct |
2 ms |
1544 KB |
Output is correct |
45 |
Correct |
3 ms |
1544 KB |
Output is correct |
46 |
Correct |
3 ms |
1544 KB |
Output is correct |
47 |
Correct |
3 ms |
1548 KB |
Output is correct |
48 |
Correct |
3 ms |
1668 KB |
Output is correct |
49 |
Correct |
3 ms |
1668 KB |
Output is correct |
50 |
Correct |
4 ms |
1668 KB |
Output is correct |
51 |
Correct |
3 ms |
1668 KB |
Output is correct |
52 |
Correct |
4 ms |
1668 KB |
Output is correct |
53 |
Correct |
3 ms |
1668 KB |
Output is correct |
54 |
Correct |
4 ms |
1668 KB |
Output is correct |
55 |
Correct |
3 ms |
1668 KB |
Output is correct |
56 |
Correct |
4 ms |
1668 KB |
Output is correct |
57 |
Correct |
3 ms |
1668 KB |
Output is correct |
58 |
Correct |
4 ms |
1668 KB |
Output is correct |
59 |
Correct |
4 ms |
1668 KB |
Output is correct |
60 |
Correct |
3 ms |
1668 KB |
Output is correct |
61 |
Correct |
3 ms |
1668 KB |
Output is correct |
62 |
Correct |
3 ms |
1668 KB |
Output is correct |
63 |
Correct |
4 ms |
1668 KB |
Output is correct |
64 |
Correct |
16 ms |
1748 KB |
Output is correct |
65 |
Correct |
5 ms |
1752 KB |
Output is correct |
66 |
Correct |
5 ms |
1760 KB |
Output is correct |
67 |
Correct |
5 ms |
1760 KB |
Output is correct |
68 |
Correct |
7 ms |
1796 KB |
Output is correct |
69 |
Correct |
7 ms |
1796 KB |
Output is correct |
70 |
Correct |
8 ms |
1796 KB |
Output is correct |
71 |
Correct |
7 ms |
1796 KB |
Output is correct |
72 |
Correct |
10 ms |
1796 KB |
Output is correct |
73 |
Correct |
8 ms |
1796 KB |
Output is correct |
74 |
Correct |
12 ms |
1796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1796 KB |
Output is correct |
2 |
Correct |
3 ms |
1796 KB |
Output is correct |
3 |
Correct |
2 ms |
1796 KB |
Output is correct |
4 |
Correct |
2 ms |
1796 KB |
Output is correct |
5 |
Correct |
4 ms |
1796 KB |
Output is correct |
6 |
Correct |
3 ms |
1796 KB |
Output is correct |
7 |
Correct |
2 ms |
1796 KB |
Output is correct |
8 |
Correct |
2 ms |
1796 KB |
Output is correct |
9 |
Correct |
3 ms |
1796 KB |
Output is correct |
10 |
Correct |
4 ms |
1800 KB |
Output is correct |
11 |
Correct |
3 ms |
1804 KB |
Output is correct |
12 |
Correct |
2 ms |
1808 KB |
Output is correct |
13 |
Correct |
3 ms |
1812 KB |
Output is correct |
14 |
Correct |
2 ms |
1816 KB |
Output is correct |
15 |
Correct |
2 ms |
1816 KB |
Output is correct |
16 |
Correct |
3 ms |
1820 KB |
Output is correct |
17 |
Correct |
4 ms |
1828 KB |
Output is correct |
18 |
Correct |
3 ms |
1832 KB |
Output is correct |
19 |
Correct |
3 ms |
1836 KB |
Output is correct |
20 |
Correct |
2 ms |
1840 KB |
Output is correct |
21 |
Correct |
2 ms |
1844 KB |
Output is correct |
22 |
Correct |
3 ms |
1848 KB |
Output is correct |
23 |
Correct |
3 ms |
1852 KB |
Output is correct |
24 |
Correct |
3 ms |
1976 KB |
Output is correct |
25 |
Correct |
3 ms |
1976 KB |
Output is correct |
26 |
Correct |
3 ms |
1976 KB |
Output is correct |
27 |
Correct |
2 ms |
1976 KB |
Output is correct |
28 |
Correct |
2 ms |
1976 KB |
Output is correct |
29 |
Correct |
3 ms |
1976 KB |
Output is correct |
30 |
Correct |
3 ms |
1976 KB |
Output is correct |
31 |
Correct |
3 ms |
1976 KB |
Output is correct |
32 |
Correct |
3 ms |
1976 KB |
Output is correct |
33 |
Correct |
2 ms |
1976 KB |
Output is correct |
34 |
Correct |
3 ms |
1976 KB |
Output is correct |
35 |
Correct |
3 ms |
1976 KB |
Output is correct |
36 |
Correct |
3 ms |
2016 KB |
Output is correct |
37 |
Correct |
5 ms |
2016 KB |
Output is correct |
38 |
Correct |
4 ms |
2016 KB |
Output is correct |
39 |
Correct |
5 ms |
2016 KB |
Output is correct |
40 |
Correct |
3 ms |
2016 KB |
Output is correct |
41 |
Correct |
4 ms |
2016 KB |
Output is correct |
42 |
Correct |
4 ms |
2060 KB |
Output is correct |
43 |
Correct |
3 ms |
2060 KB |
Output is correct |
44 |
Correct |
4 ms |
2060 KB |
Output is correct |
45 |
Correct |
3 ms |
2060 KB |
Output is correct |
46 |
Correct |
3 ms |
2060 KB |
Output is correct |
47 |
Correct |
3 ms |
2064 KB |
Output is correct |
48 |
Correct |
4 ms |
2120 KB |
Output is correct |
49 |
Correct |
3 ms |
2120 KB |
Output is correct |
50 |
Correct |
4 ms |
2120 KB |
Output is correct |
51 |
Correct |
3 ms |
2120 KB |
Output is correct |
52 |
Correct |
13 ms |
2120 KB |
Output is correct |
53 |
Correct |
18 ms |
2148 KB |
Output is correct |
54 |
Correct |
33 ms |
2148 KB |
Output is correct |
55 |
Correct |
37 ms |
2148 KB |
Output is correct |
56 |
Correct |
118 ms |
2148 KB |
Output is correct |
57 |
Correct |
116 ms |
2232 KB |
Output is correct |
58 |
Correct |
111 ms |
2232 KB |
Output is correct |
59 |
Correct |
116 ms |
2232 KB |
Output is correct |
60 |
Correct |
123 ms |
2232 KB |
Output is correct |
61 |
Correct |
3 ms |
2232 KB |
Output is correct |
62 |
Correct |
20 ms |
2232 KB |
Output is correct |
63 |
Correct |
36 ms |
2320 KB |
Output is correct |
64 |
Correct |
32 ms |
2320 KB |
Output is correct |
65 |
Correct |
59 ms |
2320 KB |
Output is correct |
66 |
Correct |
93 ms |
2352 KB |
Output is correct |
67 |
Correct |
116 ms |
2352 KB |
Output is correct |
68 |
Correct |
122 ms |
2352 KB |
Output is correct |
69 |
Correct |
114 ms |
2468 KB |
Output is correct |