結果

問題 No.34 砂漠の行商人
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-19 23:03:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,542 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 148,600 KB
実行使用メモリ 83,028 KB
最終ジャッジ日時 2023-09-11 08:34:45
合計ジャッジ時間 5,985 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
5,460 KB
testcase_02 AC 6 ms
18,100 KB
testcase_03 AC 4 ms
15,916 KB
testcase_04 AC 17 ms
41,200 KB
testcase_05 AC 18 ms
47,288 KB
testcase_06 AC 9 ms
36,744 KB
testcase_07 AC 25 ms
57,632 KB
testcase_08 AC 32 ms
68,096 KB
testcase_09 AC 246 ms
63,240 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 15 ms
43,228 KB
testcase_13 WA -
testcase_14 AC 545 ms
82,568 KB
testcase_15 AC 19 ms
45,684 KB
testcase_16 AC 53 ms
44,012 KB
testcase_17 AC 20 ms
62,396 KB
testcase_18 AC 9 ms
20,600 KB
testcase_19 AC 158 ms
79,644 KB
testcase_20 AC 283 ms
80,396 KB
testcase_21 AC 19 ms
80,272 KB
testcase_22 AC 29 ms
77,192 KB
testcase_23 AC 35 ms
52,092 KB
testcase_24 AC 386 ms
80,176 KB
testcase_25 AC 31 ms
59,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

struct State {
  int x, y, damage;
  State(int x, int y, int d): x(x), y(y), damage(d) {}
};

int N, V, SX, SY, GX, GY;
int L[100][100];
int minCost[100][100][2000];

int solve() {
  SX--;
  SY--;
  GX--;
  GY--;
  rep(i, N) rep(j, N) rep(k, V) minCost[i][j][k] = 1 << 29;

  queue<State> Q;
  Q.push(State(SX, SY, 0));
  minCost[SY][SX][0] = 0;

  while(!Q.empty()) {
    State stt = Q.front();
    Q.pop();

    if(stt.x == GX && stt.y == GY) {
      return minCost[stt.y][stt.x][stt.damage];
    }

    rep(i, 4) {
      int nx = dx[i] + stt.x;
      int ny = dy[i] + stt.y;
      if(!(0 <= nx && nx < N && 0 <= ny && ny < N)) continue;
      if(stt.damage + L[ny][nx] >= V) continue;
      if(minCost[ny][nx][stt.damage + L[ny][nx]] <= minCost[stt.y][stt.x][stt.damage] + 1) continue;
      minCost[ny][nx][stt.damage + L[ny][nx]] = minCost[stt.y][stt.x][stt.damage] + 1;
      Q.push(State(nx, ny, stt.damage + L[ny][nx]));
    }
  }

  return -1;
}

int main() {
  // ios_base::sync_with_stdio(false);
  cin >> N >> V >> SX >> SY >> GX >> GY;
  rep(i, N) rep(j, N) cin >> L[i][j];
  cout << solve() << endl;
  return 0;
}
0