結果

問題 No.2095 High Rise
ユーザー _yurimoir
提出日時 2022-10-08 09:18:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 3,439 ms
コンパイル使用メモリ 250,012 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-06-22 07:35:24
合計ジャッジ時間 6,471 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,m;
    cin>>n>>m;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    vector<vector<ll>> a(n,vector<ll>(m,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    vector<vector<ll>> dp(n,vector<ll>(m,0));
    for(int i=0;i<m;i++){
        dp[0][i]=a[0][i];
    }
    for(int i=1;i<n;i++){
        ll mn=*min_element(dp[i-1].begin(),dp[i-1].end());
        for(int j=0;j<m;j++){
            dp[i][j]=min(dp[i-1][j]+a[i][j],mn+a[i-1][j]+a[i][j]);
        }
    }
    ll ans=1e18;
    for(int i=0;i<m;i++){
        ans=min(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
}
0