이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 < (1 << (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... |