結果

問題 No.2095 High Rise
ユーザー nyyanyya
提出日時 2022-10-07 22:40:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 384 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 3,840 ms
コンパイル使用メモリ 230,152 KB
実行使用メモリ 19,152 KB
最終ジャッジ日時 2023-09-03 14:08:28
合計ジャッジ時間 7,887 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 44 ms
5,168 KB
testcase_18 AC 30 ms
4,568 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 48 ms
4,884 KB
testcase_21 AC 92 ms
6,836 KB
testcase_22 AC 384 ms
18,604 KB
testcase_23 AC 383 ms
19,152 KB
testcase_24 AC 384 ms
18,600 KB
testcase_25 AC 384 ms
18,560 KB
testcase_26 AC 384 ms
18,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
//using mint = modint;
using mint = modint998244353;
using P = pair<int, int>;

const ll INF=1LL<<60, dx[]={0,1,0,-1},dy[]={1,0,-1,0};
bool chmin(ll& a,ll b){if(a>b){a=b; return 1;} return 0;}
bool chmax(ll& a,ll b){if(a<b){a=b; return 1;} return 0;}

int main(){

    int n,m;
    cin >> n >> m;
    vector<vector<ll>> a(n,vector<ll> (m));
    rep(i,n)rep(j,m) cin >> a[i][j];

    vector<vector<ll>> dp(n+1,vector<ll> (m));

    if(n==1) {
        cout << 0 << endl;
        return 0;
    }
    
    ll lowcost = INF;
    rep(j,m){
        dp[2][j] = a[0][j]+a[1][j];
        chmin(lowcost,dp[2][j]); 
    }

    for(int i=3;i<=n;i++){
        ll tmp=INF;
        rep(j,m){
            dp[i][j] = min(lowcost+a[i-2][j],dp[i-1][j]) +a[i-1][j];
            chmin(tmp,dp[i][j]);
        }
        lowcost = tmp;
    }

    ll ans = INF;
    rep(i,m) chmin(ans,dp[n][i]);
    cout << ans << endl;

    return 0;
}
0