#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
//-----------------------
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mem(f,x) memset(f, x, sizeof(f))
#define __lcm(a, b) (1ll * a * b) / __gcd(a, b)
#define bit(mask, i) ((mask >> i) & 1)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define el '\n'
#define F first
#define S second
#define io(x) freopen(x".inp","r",stdin),freopen(x".out","w",stdout)
//-----------------------
const ll INF = 1e18;
const int MOD = 1e9 + 7;
const int MULTI = 0;
const int dx[4] = {0, 0, 1, -1}; //R L D U
const int dy[4] = {1, -1, 0, 0};
//-----AUTHOR trvhung VNG High School for Gifted Student-----
const int LOG = 40;
const int maxn = 2e3 + 5;
int n, A, B, a[maxn];
bool ok(ll mask, ll prev, ll pos) {
ll temp = (mask >> pos << pos) | prev;
return temp == prev;
}
namespace onetwo {
ll dp[maxn][maxn], pref[maxn], sum;
map<ll, set<ll> > v[maxn];
bool check() {
return n <= 50;
}
void solve() {
for (int i = 1; i <= n; ++i)
pref[i] = pref[i - 1] + a[i];
sum = 0;
for (int i = 1; i <= n; ++i) {
sum += a[i];
dp[i][1] = sum;
v[i][1].insert(dp[i][1]);
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= min(i, B); ++j) {
if (j == 1) continue;
dp[i][j] = INF; sum = a[i];
for (int k = i - 1; k >= j - 1; --k) {
for (auto x: v[k][j - 1]) {
dp[i][j] = min(dp[i][j], x | sum);
v[i][j].insert(x | sum);
}
sum += a[k];
}
}
ll res = INF;
for (int i = A; i <= B; ++i)
res = min(res, dp[n][i]);
cout << res;
}
}
namespace threefour {
bool check() {
return n <= 100;
}
const int maxn = 1e2 + 5;
bool dp[maxn][maxn]; ll prev = 0;
void solve() {
for (int j = LOG; j >= 0; --j) {
mem(dp, false); dp[0][0] = true;
for (int i = 1; i <= n; ++i)
for (int k = 1; k <= i; ++k) {
ll sum = 0;
for (int z = i; z >= 1; --z) {
sum += a[z];
if (ok(sum, prev, j))
dp[i][k] |= dp[z - 1][k - 1];
}
}
bool check = false;
for (int i = A; i <= B; ++i)
if (dp[n][i])
check = true;
if (!check) prev += (1ll << j);
}
cout << prev;
}
}
namespace five {
ll prev = 0, dp[maxn];
void solve() {
for (int j = LOG; j >= 0; --j) {
for (int i1 = 1; i1 <= n; ++i1)
dp[i1] = INF;
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
ll sum = 0;
for (int z = i; z >= 1; --z) {
sum += a[z];
if (ok(sum, prev, j))
dp[i] = min(dp[i], dp[z - 1] + 1);
}
}
if (dp[n] > B) prev += (1ll << j);
}
cout << prev;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; ++i)
cin >> a[i];
if (onetwo::check()) return onetwo::solve(), 0;
if (threefour::check()) return threefour::solve(), 0;
five::solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2632 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
7 ms |
3104 KB |
Output is correct |
31 |
Correct |
16 ms |
4008 KB |
Output is correct |
32 |
Correct |
8 ms |
3164 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
11 ms |
3492 KB |
Output is correct |
35 |
Correct |
10 ms |
3420 KB |
Output is correct |
36 |
Correct |
8 ms |
3124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
2652 KB |
Output is correct |
17 |
Correct |
6 ms |
3164 KB |
Output is correct |
18 |
Correct |
17 ms |
3716 KB |
Output is correct |
19 |
Correct |
9 ms |
3160 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
11 ms |
3420 KB |
Output is correct |
22 |
Correct |
10 ms |
3420 KB |
Output is correct |
23 |
Correct |
9 ms |
3164 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
7 ms |
348 KB |
Output is correct |
26 |
Correct |
14 ms |
576 KB |
Output is correct |
27 |
Correct |
19 ms |
344 KB |
Output is correct |
28 |
Correct |
25 ms |
348 KB |
Output is correct |
29 |
Correct |
24 ms |
348 KB |
Output is correct |
30 |
Correct |
25 ms |
344 KB |
Output is correct |
31 |
Correct |
27 ms |
344 KB |
Output is correct |
32 |
Correct |
25 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2800 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2648 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
7 ms |
3164 KB |
Output is correct |
41 |
Correct |
16 ms |
3776 KB |
Output is correct |
42 |
Correct |
8 ms |
3164 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
13 ms |
3676 KB |
Output is correct |
45 |
Correct |
10 ms |
3416 KB |
Output is correct |
46 |
Correct |
8 ms |
3164 KB |
Output is correct |
47 |
Correct |
3 ms |
348 KB |
Output is correct |
48 |
Correct |
7 ms |
348 KB |
Output is correct |
49 |
Correct |
12 ms |
348 KB |
Output is correct |
50 |
Correct |
19 ms |
580 KB |
Output is correct |
51 |
Correct |
25 ms |
344 KB |
Output is correct |
52 |
Correct |
24 ms |
344 KB |
Output is correct |
53 |
Correct |
27 ms |
604 KB |
Output is correct |
54 |
Correct |
24 ms |
344 KB |
Output is correct |
55 |
Correct |
25 ms |
348 KB |
Output is correct |
56 |
Correct |
3 ms |
348 KB |
Output is correct |
57 |
Correct |
8 ms |
576 KB |
Output is correct |
58 |
Correct |
13 ms |
576 KB |
Output is correct |
59 |
Correct |
16 ms |
344 KB |
Output is correct |
60 |
Correct |
17 ms |
576 KB |
Output is correct |
61 |
Correct |
16 ms |
348 KB |
Output is correct |
62 |
Correct |
17 ms |
580 KB |
Output is correct |
63 |
Correct |
17 ms |
344 KB |
Output is correct |
64 |
Correct |
19 ms |
344 KB |
Output is correct |
65 |
Correct |
3 ms |
348 KB |
Output is correct |
66 |
Correct |
5 ms |
348 KB |
Output is correct |
67 |
Correct |
8 ms |
348 KB |
Output is correct |
68 |
Correct |
12 ms |
344 KB |
Output is correct |
69 |
Correct |
16 ms |
348 KB |
Output is correct |
70 |
Correct |
15 ms |
344 KB |
Output is correct |
71 |
Correct |
16 ms |
344 KB |
Output is correct |
72 |
Correct |
18 ms |
344 KB |
Output is correct |
73 |
Correct |
19 ms |
348 KB |
Output is correct |
74 |
Correct |
17 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2904 KB |
Output is correct |
27 |
Correct |
7 ms |
3164 KB |
Output is correct |
28 |
Correct |
16 ms |
3676 KB |
Output is correct |
29 |
Correct |
8 ms |
3296 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
13 ms |
3420 KB |
Output is correct |
32 |
Correct |
11 ms |
3272 KB |
Output is correct |
33 |
Correct |
9 ms |
3160 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
7 ms |
348 KB |
Output is correct |
36 |
Correct |
12 ms |
348 KB |
Output is correct |
37 |
Correct |
19 ms |
600 KB |
Output is correct |
38 |
Correct |
25 ms |
348 KB |
Output is correct |
39 |
Correct |
24 ms |
348 KB |
Output is correct |
40 |
Correct |
25 ms |
348 KB |
Output is correct |
41 |
Correct |
25 ms |
348 KB |
Output is correct |
42 |
Correct |
25 ms |
348 KB |
Output is correct |
43 |
Correct |
3 ms |
344 KB |
Output is correct |
44 |
Correct |
8 ms |
348 KB |
Output is correct |
45 |
Correct |
12 ms |
572 KB |
Output is correct |
46 |
Correct |
16 ms |
344 KB |
Output is correct |
47 |
Correct |
15 ms |
348 KB |
Output is correct |
48 |
Correct |
17 ms |
344 KB |
Output is correct |
49 |
Correct |
17 ms |
348 KB |
Output is correct |
50 |
Correct |
17 ms |
344 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
9 ms |
348 KB |
Output is correct |
53 |
Correct |
14 ms |
584 KB |
Output is correct |
54 |
Correct |
26 ms |
348 KB |
Output is correct |
55 |
Correct |
32 ms |
592 KB |
Output is correct |
56 |
Correct |
87 ms |
348 KB |
Output is correct |
57 |
Correct |
89 ms |
344 KB |
Output is correct |
58 |
Correct |
84 ms |
348 KB |
Output is correct |
59 |
Correct |
88 ms |
604 KB |
Output is correct |
60 |
Correct |
84 ms |
604 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
12 ms |
348 KB |
Output is correct |
63 |
Correct |
26 ms |
348 KB |
Output is correct |
64 |
Correct |
24 ms |
604 KB |
Output is correct |
65 |
Correct |
45 ms |
348 KB |
Output is correct |
66 |
Correct |
65 ms |
604 KB |
Output is correct |
67 |
Correct |
82 ms |
604 KB |
Output is correct |
68 |
Correct |
95 ms |
580 KB |
Output is correct |
69 |
Correct |
90 ms |
600 KB |
Output is correct |