#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define chkmin(a, b) a = min(a, b)
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const ll infinity = 1e18;
int main() {
int n, m;
cin >> n >> m;
vi dig1(m + n - 1), dig2(n + m - 1);
for (int i = 0; i < m + n - 1; i++) {
cin >> dig2[i];
}
for (int i = 0; i < n + m - 1; i++) {
cin >> dig1[i];
}
// ll ans = 0;
// for (int i = 0; i < m; i++) {
// ans += min(dig1[m - i - 1], dig2[i]);
// }
ll ans1 = infinity, ans2 = infinity;
for (int i = 0; i < (1 << ((n + m) / 2)); i++) {
ll curr = 0;
vb visit_dig1(n + m - 1);
for (int j = 0; j < (n + m) / 2; j++) {
if ((i >> j) & 1) {
curr += dig1[2 * j];
visit_dig1[2 * j] = true;
}
}
vb visit_dig2(n + m - 1);
for (int j = 0; j < n; j++) {
for (int k = 0; k < m; k++) {
if (!visit_dig1[j + k] && !((j + k) & 1)) {
visit_dig2[j - k + m - 1] = true;
}
}
}
for (int j = 0; j < n + m - 1; j++) {
if (visit_dig2[j]) curr += dig2[j];
}
chkmin(ans1, curr);
}
for (int i = 0; i < (1 << ((n + m - 1) / 2)); i++) {
ll curr = 0;
vb visit_dig1(n + m - 1);
for (int j = 0; j < (n + m - 1) / 2; j++) {
if ((i >> j) & 1) {
curr += dig1[2 * j + 1];
visit_dig1[2 * j + 1] = true;
}
}
vb visit_dig2(n + m - 1);
for (int j = 0; j < n; j++) {
for (int k = 0; k < m; k++) {
if (!visit_dig1[j + k] && ((j + k) & 1)) {
visit_dig2[j - k + m - 1] = true;
}
}
}
for (int j = 0; j < n + m - 1; j++) {
if (visit_dig2[j]) curr += dig2[j];
}
chkmin(ans2, curr);
}
cout << ans1 + ans2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1853 ms |
272 KB |
Output is correct |
21 |
Correct |
33 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1154 ms |
272 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1837 ms |
272 KB |
Output is correct |
26 |
Correct |
1785 ms |
272 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
4 ms |
288 KB |
Output is correct |
29 |
Correct |
10 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1853 ms |
272 KB |
Output is correct |
21 |
Correct |
33 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1154 ms |
272 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1837 ms |
272 KB |
Output is correct |
26 |
Correct |
1785 ms |
272 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
4 ms |
288 KB |
Output is correct |
29 |
Correct |
10 ms |
204 KB |
Output is correct |
30 |
Execution timed out |
2085 ms |
332 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
182 ms |
3660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2091 ms |
6900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1853 ms |
272 KB |
Output is correct |
21 |
Correct |
33 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1154 ms |
272 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1837 ms |
272 KB |
Output is correct |
26 |
Correct |
1785 ms |
272 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
4 ms |
288 KB |
Output is correct |
29 |
Correct |
10 ms |
204 KB |
Output is correct |
30 |
Execution timed out |
2085 ms |
332 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |