結果
問題 | No.2328 Build Walls |
ユーザー |
![]() |
提出日時 | 2023-05-28 14:44:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 985 bytes |
コンパイル時間 | 1,108 ms |
コンパイル使用メモリ | 108,856 KB |
最終ジャッジ日時 | 2025-02-13 11:58:22 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 15 |
ソースコード
// I SELL YOU...! #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<chrono> #include<iomanip> #include<map> #include<set> using namespace std; using ll = long long; using P = pair<ll,ll>; using TP = tuple<ll,ll,ll>; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } const ll INF = 1e9; signed main(){ init_io(); ll h,w; cin >> h >> w; vector<vector<ll>> a(h, vector<ll>(w, -1)); vector<vector<ll>> dp(h, vector<ll>(w, INF)); for(int i=1;i<h-1;i++){ for(int j=0;j<w;j++) { cin >> a[i][j]; if (j==0 && a[i][j] != -1) dp[i][j] = a[i][j]; } } for (int j=1;j<w;j++) { for (int i=1;i<h-1;i++) { if (a[i][j] == -1) continue; dp[i][j] = a[i][j] + min(dp[i-1][j-1], min(dp[i][j-1], dp[i+1][j-1])); } } ll ans = INF; for (int i=0;i<h;i++) { ans = min(ans, dp[i][w-1]); } if (ans == INF) ans = -1; cout << ans << endl; }