#ifdef LOCAL
#define _GLIBCXX_DEBUG
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,popcnt")
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> istream& operator>>(istream& in, vector<T>& v);
template<typename T> ostream& operator<<(ostream& out, const vector<T>& v);
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p);
template<typename T1, typename T2> ostream& operator<<(ostream& out, const pair<T1, T2>& p);
istream& operator>>(istream& in, vector<bool>& v) { bool n; for (auto&& i : v) { in >> n; i = n; } return in; }
ostream& operator<<(ostream& out, const vector<bool>& v) { for (auto i : v) { out << i << " "; } return out; }
template<typename T> istream& operator>>(istream& in, vector<T>& v) { for (auto& x : v) in >> x; return in; }
template<typename T> ostream& operator<<(ostream& out, const vector<T>& v) { for (auto& x : v) out << x << " "; return out; }
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) { in >> p.first >> p.second; return in; }
template<typename T1, typename T2> ostream& operator<<(ostream& out, const pair<T1, T2>& p) { out << p.first << " " << p.second; return out; }
mt19937_64 rnd((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef long double ld;
#define QUICK_IO
//#define MULTIPLE_TESTCASES
//#define FILESTREAM
void solve() {
int n, m;
cin >> n >> m;
vector<ll> a(n), b(m);
cin >> a >> b;
vector<vector<ll>> dp(n, vector<ll>(m, 1e18));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + b[j]);
if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + a[i]);
}
}
cout << dp[n - 1][m - 1];
}
signed main() {
#ifndef LOCAL
#ifdef QUICK_IO
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
#ifdef FILESTREAM
freopen("solve.in", "r", stdin);
freopen("solve.out", "w", stdout);
#endif
#endif
cout << setprecision(9) << fixed;
unsigned t = 1;
#ifdef MULTIPLE_TESTCASES
cin >> t;
#endif
for (unsigned i = 1; i <= t; ++i) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
10 |
Correct |
7 ms |
8284 KB |
Output is correct |
11 |
Correct |
7 ms |
8332 KB |
Output is correct |
12 |
Correct |
7 ms |
8284 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
7 ms |
8284 KB |
Output is correct |
15 |
Correct |
7 ms |
8284 KB |
Output is correct |
16 |
Correct |
7 ms |
8280 KB |
Output is correct |
17 |
Correct |
8 ms |
8280 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
3496 KB |
Output is correct |
4 |
Runtime error |
490 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
10 |
Correct |
7 ms |
8284 KB |
Output is correct |
11 |
Correct |
7 ms |
8332 KB |
Output is correct |
12 |
Correct |
7 ms |
8284 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
7 ms |
8284 KB |
Output is correct |
15 |
Correct |
7 ms |
8284 KB |
Output is correct |
16 |
Correct |
7 ms |
8280 KB |
Output is correct |
17 |
Correct |
8 ms |
8280 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
3496 KB |
Output is correct |
32 |
Runtime error |
490 ms |
1048576 KB |
Execution killed with signal 9 |
33 |
Halted |
0 ms |
0 KB |
- |