제출 #1158295

#제출 시각아이디문제언어결과실행 시간메모리
1158295Zero_OPSightseeing in Kyoto (JOI22_kyoto)C++20
10 / 100
477 ms1114112 KiB
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define ROF(i, r, l) for(int i = (r) - 1; i >= (l); --i)

#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define sz(v) (int)v.size()
#define pb push_back
#define eb emplace_back
#define compact(v) v.erase(unique(all(v)), end(v))

#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second

#define dbg(x) "[" #x " = " << (x) << "]"
#define readFile(task) freopen(task, "r", stdin)
#define writeFile(task) freopen(task, "w", stdout)

template<typename T>
      bool minimize(T& a, const T& b){
            if(a > b) return a = b, true;
            return false;
      }

template<typename T>
      bool maximize(T& a, const T& b){
            if(a < b) return a = b, true;
            return false;
      }

using ll = long long;
using db = double;
using ld = long double;
using ull = unsigned long long;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;

using vi = vector<int>;
using vb = vector<bool>;
using vstr = vector<string>;
using vl = vector<ll>;
using vd = vector<double>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

void setIO(){
      ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
      readFile("task.inp");
      writeFile("task.out");
#endif //LOCAL
}

const ll inf = 1e18;

int main(){
      setIO();

      int H, W;
      cin >> H >> W;

      vi A(H), B(W);
      FOR(i, 0, H) cin >> A[i];
      FOR(i, 0, W) cin >> B[i];

      vector<vl> dp(H, vl(W, inf));
      dp[0][0] = 0;
      FOR(i, 0, H){
            FOR(j, 0, W){
                  if(i > 0) minimize(dp[i][j], dp[i-1][j] + B[j]);
                  if(j > 0) minimize(dp[i][j], dp[i][j-1] + A[i]);
//                  cout << dbg(i) << dbg(j) << dbg(dp[i][j]) << '\n';
            }
      }

      cout << dp[H-1][W-1] << '\n';

      return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...