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 <bits/stdc++.h>
#define endl "\n"
#define int long long
#define see(x) cerr<<#x<<"="<<x<<endl;
using namespace std;
int m, n, a[10000], b[10000], g[1000][1000];
int32_t main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> m >> n;
for (int i = 0; i < m+n-1; ++ i)
cin >> a[i];
for (int i = 0; i < m+n-1; ++ i)
cin >> b[i];
int ans = 1e18;
for (int i = 1; i < (1LL << (m+m+n+n-2)); ++ i) {
int k = i, x = 0, y = n-1, sum = 0;
for (int i = 0; i < m; ++ i)
for (int j = 0; j < n; ++ j)
g[i][j] = 0;
for (int j = 0; j < m+n-1; ++ j) {
if (k & 1) {
sum += a[j];
for (int xx = x, yy = y; xx <= m-1 and yy <= n-1; ++ xx, ++ yy)
g[xx][yy] = 1;
}
k >>= 1;
if (y > 0) -- y;
else ++ x;
}
x = y = 0;
for (int j = 0; j < m+n-1; ++ j) {
if (k & 1) {
sum += b[j];
for (int xx = x, yy = y; xx <= m-1 and yy >= 0; ++ xx, -- yy)
g[xx][yy] = 1;
}
k >>= 1;
if (y < n-1) ++ y;
else ++ x;
}
int f = 1;
for (int i = 0; i < m; ++ i)
for (int j = 0; j < n; ++ j)
f &= g[i][j];
if (f) ans = min(ans, sum);
}
cout << ans << endl;
return 0;
}
# | 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... |