結果

問題 No.2328 Build Walls
ユーザー cho435cho435
提出日時 2023-05-28 17:01:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 826 ms / 3,000 ms
コード長 1,017 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 215,116 KB
実行使用メモリ 11,048 KB
最終ジャッジ日時 2023-08-27 14:22:00
合計ジャッジ時間 9,531 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 62 ms
7,284 KB
testcase_14 AC 199 ms
5,600 KB
testcase_15 AC 111 ms
5,464 KB
testcase_16 AC 16 ms
4,376 KB
testcase_17 AC 89 ms
6,076 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 53 ms
7,176 KB
testcase_22 AC 336 ms
6,372 KB
testcase_23 AC 432 ms
10,860 KB
testcase_24 AC 382 ms
10,836 KB
testcase_25 AC 439 ms
10,852 KB
testcase_26 AC 279 ms
10,888 KB
testcase_27 AC 346 ms
10,920 KB
testcase_28 AC 105 ms
10,700 KB
testcase_29 AC 431 ms
11,048 KB
testcase_30 AC 116 ms
10,704 KB
testcase_31 AC 112 ms
10,664 KB
testcase_32 AC 351 ms
10,824 KB
testcase_33 AC 826 ms
10,908 KB
testcase_34 AC 119 ms
10,712 KB
testcase_35 AC 544 ms
10,860 KB
testcase_36 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)

int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<int>> a(h-2,vector<int>(w));
  rep(i,h-2) rep(j,w) cin>>a.at(i).at(j);
  vector<vector<ll>> dp(h-2,vector<ll>(w+1,1e18));
  priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> q;
  rep(i,h-2) if(a.at(i).at(0)!=-1) q.push({a.at(i).at(0),{i,0}});
  vector<int> dx={0,1,0,-1,1,-1,-1,1};
  vector<int> dy={1,0,-1,0,1,1,-1,-1};
  auto isok=[&](int x,int y){
    return 0<=x&&x<h-2&&0<=y&&y<w;
  };
  while(!q.empty()){
    auto [sc,p]=q.top();
    q.pop();
    auto [x,y]=p;
    if(dp.at(x).at(y)!=1e18) continue;
    dp.at(x).at(y)=sc;
    rep(i,8){
      int nx=x+dx.at(i);
      int ny=y+dy.at(i);
      if(isok(nx,ny)&&a.at(nx).at(ny)!=-1) q.push({sc+a.at(nx).at(ny),{nx,ny}});
    }
  }
  ll ans=1e18;
  rep(i,h-2){
    ans=min(ans,dp.at(i).at(w-1));
  }
  if(ans==1e18) ans=-1;
  cout<<ans<<endl;
}
0