結果

問題 No.2095 High Rise
ユーザー 7iz67iz6
提出日時 2022-10-22 02:13:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 2,395 ms
コンパイル使用メモリ 169,852 KB
実行使用メモリ 19,244 KB
最終ジャッジ日時 2023-09-14 01:31:03
合計ジャッジ時間 6,686 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,332 KB
testcase_01 AC 7 ms
11,244 KB
testcase_02 AC 7 ms
11,280 KB
testcase_03 AC 6 ms
11,432 KB
testcase_04 AC 6 ms
11,236 KB
testcase_05 AC 6 ms
11,252 KB
testcase_06 AC 5 ms
11,240 KB
testcase_07 AC 6 ms
11,324 KB
testcase_08 AC 6 ms
11,496 KB
testcase_09 AC 7 ms
11,280 KB
testcase_10 AC 7 ms
11,352 KB
testcase_11 AC 7 ms
11,264 KB
testcase_12 AC 8 ms
11,460 KB
testcase_13 AC 7 ms
11,344 KB
testcase_14 AC 8 ms
11,328 KB
testcase_15 AC 7 ms
11,340 KB
testcase_16 AC 7 ms
11,248 KB
testcase_17 AC 43 ms
12,208 KB
testcase_18 AC 30 ms
11,904 KB
testcase_19 AC 11 ms
11,460 KB
testcase_20 AC 46 ms
12,196 KB
testcase_21 AC 84 ms
13,108 KB
testcase_22 AC 340 ms
19,244 KB
testcase_23 AC 335 ms
19,072 KB
testcase_24 AC 332 ms
19,076 KB
testcase_25 AC 334 ms
19,072 KB
testcase_26 AC 356 ms
19,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL<<60;
vector<vector<ll>> dp(1006, vector<ll>(1006, INF));

int main() {
    int N, M; cin >> N >> M;
    ll a[N][M];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < M; i++) {
    if(N == 1) {
        cout << 0 << endl;
        return 0;
    }
        dp[0][i] = a[0][i];
    }
    for(int i = 1; i < N; i++) {
        int midx = -1;
        ll mval = INF;
        for(int j = 0; j < M; j++) {
            if(dp[i-1][j] < mval) {
                mval = dp[i-1][j];
                midx = j;
            }
        }
        for(int j = 0; j < M; j++) {
            dp[i][j] = min({dp[i][j], dp[i-1][j] + a[i][j], mval + a[i-1][j] + a[i][j]});
        }
    }
    ll ans = INF;
    for(int i = 0; i < M; i++) {
        ans = min(ans, dp[N-1][i]);
    }
    cout << ans << endl;
}
0