結果

問題 No.2095 High Rise
ユーザー baLoon8128
提出日時 2022-10-07 21:52:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 414 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 4,013 ms
コンパイル使用メモリ 233,684 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-06-12 07:05:25
合計ジャッジ時間 7,899 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

int main() {
    int n, m;
    cin >> n >> m;
    vvi a(n, vi(m));
    rep(i, n) rep(j, m) cin >> a[i][j];
    if (n == 1) {
        cout << 0 << endl;
    } else {
        vector<vector<ll>> dp(n + 1, vector<ll>(m));
        rep(i, n) {
            rep(j, m) dp[i + 1][j] = dp[i][j] + a[i][j];
            ll mi = *min_element(dp[i + 1].begin(), dp[i + 1].end());
            rep(j, m) dp[i + 1][j] = min(dp[i + 1][j], mi + a[i][j]);
        }
        ll ret = *min_element(dp[n].begin(), dp[n].end());
        cout << ret << endl;
    }
    return 0;
}
0