#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, m;
void solve_n_1() {
vector<ll> a(n + m - 1, 0);
vector<ll> b(n + m - 1, 0);
for(ll &x : a) cin >> x;
for(ll &x : b) cin >> x;
reverse(b.begin(), b.end());
ll ans = 0;
for(int i = 0; i < n + m - 1; ++i) ans += min(a[i], b[i]);
cout << ans << "\n";
}
void solve_bf_1010() {
int p = n + m - 1;
vector<ll> a(p, 0);
vector<ll> b(p, 0);
for(ll &x : a) cin >> x;
for(ll &x : b) cin >> x;
vector<vector<bool> > colored(1 + n, vector<bool> (1 + m, false));
vector<bool> chosen(p, false);
vector<bool> paid(p, false);
ll ans = LLONG_MAX, cur = 0;
for(int mask = 0; mask < (1 << p); ++mask) {
cur = 0;
for(int i = 0; i < p; ++i) {
if(mask & (1 << i)) {
chosen[i] = true;
cur += a[i];
}
}
for(int i = 0; i < p; ++i) {
if(chosen[i]) {
int y = m - i;
int x = 1;
if(y <= 0) {
int z = 1 - y;
x += z;
y += z;
}
while(x <= n && y <= m) {
colored[x][y] = true;
++x;
++y;
}
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(!colored[i][j]) {
paid[i + j - 2] = true;
}
}
}
for(int i = 0; i < p; ++i) {
if(paid[i]) {
cur += b[i];
}
}
ans = min(ans, cur);
chosen.assign(p, false);
paid.assign(p, false);
colored.assign(1 + n, vector<bool> (1 + m, false));
}
cout << ans << "\n";
}
void solve() {
cin >> n >> m;
if(n == 1) {
solve_n_1();
return;
}
if(n <= 20 && m <= 20) {
solve_bf_1010();
return;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
1 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 |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
1 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 |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
629 ms |
288 KB |
Output is correct |
12 |
Correct |
12 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
308 KB |
Output is correct |
16 |
Correct |
650 ms |
292 KB |
Output is correct |
17 |
Correct |
7 ms |
204 KB |
Output is correct |
18 |
Correct |
648 ms |
292 KB |
Output is correct |
19 |
Correct |
294 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
1 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 |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
629 ms |
288 KB |
Output is correct |
12 |
Correct |
12 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
308 KB |
Output is correct |
16 |
Correct |
650 ms |
292 KB |
Output is correct |
17 |
Correct |
7 ms |
204 KB |
Output is correct |
18 |
Correct |
648 ms |
292 KB |
Output is correct |
19 |
Correct |
294 ms |
292 KB |
Output is correct |
20 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
1 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 |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
629 ms |
288 KB |
Output is correct |
12 |
Correct |
12 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
308 KB |
Output is correct |
16 |
Correct |
650 ms |
292 KB |
Output is correct |
17 |
Correct |
7 ms |
204 KB |
Output is correct |
18 |
Correct |
648 ms |
292 KB |
Output is correct |
19 |
Correct |
294 ms |
292 KB |
Output is correct |
20 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
3436 KB |
Output is correct |
2 |
Correct |
52 ms |
3436 KB |
Output is correct |
3 |
Correct |
53 ms |
3332 KB |
Output is correct |
4 |
Correct |
55 ms |
3404 KB |
Output is correct |
5 |
Correct |
68 ms |
3436 KB |
Output is correct |
6 |
Correct |
51 ms |
3440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
1 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 |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
629 ms |
288 KB |
Output is correct |
12 |
Correct |
12 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
308 KB |
Output is correct |
16 |
Correct |
650 ms |
292 KB |
Output is correct |
17 |
Correct |
7 ms |
204 KB |
Output is correct |
18 |
Correct |
648 ms |
292 KB |
Output is correct |
19 |
Correct |
294 ms |
292 KB |
Output is correct |
20 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |