This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |