結果

問題 No.34 砂漠の行商人
ユーザー oxyshoweroxyshower
提出日時 2019-02-28 13:43:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 1,729 ms
コンパイル使用メモリ 172,128 KB
実行使用メモリ 162,208 KB
最終ジャッジ日時 2023-09-05 16:08:39
合計ジャッジ時間 6,330 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
7,672 KB
testcase_02 AC 9 ms
34,340 KB
testcase_03 AC 7 ms
30,176 KB
testcase_04 AC 24 ms
79,744 KB
testcase_05 AC 27 ms
92,244 KB
testcase_06 AC 16 ms
71,340 KB
testcase_07 AC 36 ms
112,692 KB
testcase_08 WA -
testcase_09 AC 235 ms
123,240 KB
testcase_10 AC 56 ms
160,172 KB
testcase_11 AC 464 ms
161,804 KB
testcase_12 AC 23 ms
82,120 KB
testcase_13 AC 826 ms
162,208 KB
testcase_14 AC 639 ms
159,428 KB
testcase_15 AC 23 ms
86,792 KB
testcase_16 AC 50 ms
85,276 KB
testcase_17 AC 30 ms
121,872 KB
testcase_18 AC 12 ms
39,336 KB
testcase_19 AC 194 ms
153,940 KB
testcase_20 AC 337 ms
158,884 KB
testcase_21 AC 34 ms
157,616 KB
testcase_22 AC 39 ms
148,828 KB
testcase_23 AC 26 ms
101,216 KB
testcase_24 AC 450 ms
155,448 KB
testcase_25 AC 42 ms
117,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
int board[100][100];
int dp[100][100][2001]; //{y,x,HP} = 移動回数

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,V,Sx,Sy,Gx,Gy; cin >> N >> V >> Sx >> Sy >> Gx >> Gy;
  Sx--,Sy--,Gx--,Gy--;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> board[i][j];
    }
  }

  V = min(V,2000LL);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      fill(dp[i][j],dp[i][j]+V,-1);
    }
  }
  dp[Sy][Sx][V] = 0;
  queue< tuple<int,int,int> > q;
  q.push({Sy,Sx,V});
  while(!q.empty()){
    auto p = q.front(); q.pop();
    int y = get<0>(p);
    int x = get<1>(p);
    int v = get<2>(p);
    for(int i = 0; i < 4; i++){
      int ny = y + dy[i];
      int nx = x + dx[i];
      if(ny < 0 || N <= ny || nx < 0 || N <= nx) continue;
      int nv = v - board[ny][nx];
      if(nv <= 0) continue;
      if(dp[ny][nx][nv] != -1) continue;
      dp[ny][nx][nv] = dp[y][x][v] + 1;
      if(ny == Gy && nx == Gx){
        cout << dp[ny][nx][nv] << endl;
        return 0;
      }
      q.push({ny,nx,nv});
    }
  }
  cout << -1 << endl;

  return 0;
}
0