結果
| 問題 |
No.2095 High Rise
|
| コンテスト | |
| ユーザー |
nyya
|
| 提出日時 | 2022-10-07 22:40:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 357 ms / 2,000 ms |
| コード長 | 1,068 bytes |
| コンパイル時間 | 3,577 ms |
| コンパイル使用メモリ | 232,756 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2024-06-12 19:52:31 |
| 合計ジャッジ時間 | 6,443 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#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;
}
nyya