이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
vector<vector<ll>> v;
ll h, w; vector<ll> x, y;
ll f(ll a, ll b){
if(a<0 || a>=h || b<0 || b>=w) return -1;
return v[a][b];
}
int main() {
cin >> h >> w;
x.resize(h); y.resize(w);
for(auto& u : x) cin >> u;
for(auto& u : y) cin >> u;
v.assign(h+1, vector<ll>(w+1, -1));
v[0][0]=0;
for(ll i=0; i<h; i++){
for(ll j=0; j<w; j++){
if(i==0 && j==0) continue;
ll a=f(i-1, j), b=f(i, j-1);
if(a==-1) v[i][j]=b+x[i];
else if(b==-1) v[i][j]=a+y[j];
else v[i][j]=min(a+y[j], b+x[i]);
}
}
cout << v[h-1][w-1] << endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |