結果
| 問題 | 
                            No.2328 Build Walls
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tnakao0123
                         | 
                    
| 提出日時 | 2023-06-26 17:41:16 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,008 bytes | 
| コンパイル時間 | 342 ms | 
| コンパイル使用メモリ | 42,880 KB | 
| 実行使用メモリ | 8,264 KB | 
| 最終ジャッジ日時 | 2024-07-03 12:35:53 | 
| 合計ジャッジ時間 | 2,836 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 WA * 15 | 
ソースコード
/* -*- coding: utf-8 -*-
 *
 * 2328.cc:  No.2328 Build Walls - yukicoder
 */
#include<cstdio>
#include<algorithm>
 
using namespace std;
/* constant */
const int MAX_H = 800;
const int MAX_W = 800;
const int INF = 1 << 30;
/* typedef */
/* global variables */
int as[MAX_H][MAX_W], dp[MAX_H][MAX_W];
/* subroutines */
/* main */
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  h -= 2;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) scanf("%d", as[i] + j);
  
  for (int i = 0; i < h; i++)
    dp[i][0] = (as[i][0] >= 0) ? as[i][0] : INF;
  
  for (int j = 1; j < w; j++)
    for (int i = 0; i < h; i++) {
      if (as[i][j] >= 0) {
	int d0 = (i > 0) ? dp[i - 1][j - 1] : INF;
	int d1 = dp[i][j - 1];
	int d2 = (i + 1 < h) ? dp[i + 1][j - 1] : INF;
	dp[i][j] = min(min(d0, d1), d2) + as[i][j];
      }
      else
	dp[i][j] = INF;
    }
  int mind = INF;
  for (int i = 0; i < h; i++)
    mind = min(mind, dp[i][w - 1]);
  printf("%d\n", (mind < INF) ? mind : -1);
  return 0;
}
            
            
            
        
            
tnakao0123