結果
問題 |
No.2095 High Rise
|
ユーザー |
|
提出日時 | 2022-10-07 23:25:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 120 ms / 2,000 ms |
コード長 | 921 bytes |
コンパイル時間 | 2,124 ms |
コンパイル使用メモリ | 198,816 KB |
最終ジャッジ日時 | 2025-02-08 00:01:12 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef _RUTHEN #include <debug.hpp> #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template <class T> using V = vector<T>; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; V<V<ll>> A(N, V<ll>(M)); rep(i, N) rep(j, M) cin >> A[i][j]; if (N == 1) { cout << 0 << '\n'; return 0; } const ll INF = 1LL << 60; V<ll> dp(M, INF); rep(i, M) dp[i] = A[0][i]; for (int i = 1; i < N; i++) { V<ll> np(M, INF); ll mn = *min_element(dp.begin(), dp.end()); show(mn); rep(j, M) np[j] = mn + A[i - 1][j] + A[i][j]; rep(j, M) np[j] = min(np[j], dp[j] + A[i][j]); swap(dp, np); show(dp); } ll ans = *min_element(dp.begin(), dp.end()); cout << ans << '\n'; return 0; }