結果

問題 No.20 砂漠のオアシス
ユーザー togatogatogatoga
提出日時 2015-09-12 14:25:50
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,864 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 168,304 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:43:18
合計ジャッジ時間 3,630 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;


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

struct Edge{
  int node,cost;
  Edge(int node, int cost):node(node),cost(cost){
  }
};

struct State{
  int hp,node;
  bool use;
  State(int node, int hp, bool use):hp(hp),node(node),use(use){}
  bool operator < (const State& right) const {
    return hp < right.hp;

  }
};


int N,V,gx,gy;
int board[220][220];
int cost[4400][2];
vector<Edge> Edges[4400];

int main(){
  cin >> N >> V >> gx >> gy;
  gx--;
  gy--;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> board[i][j];
    }
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      int ny,nx;
      int node = i * N + j;
      for (int k = 0; k < 4; k++){
	ny = i + dy[k];
	nx = j + dx[k];
	if (ny < 0 or nx < 0 or ny >= N or nx >= N)continue;
	int next_node = ny * N + nx;
	int cost = board[ny][nx];
	Edges[node].push_back(Edge(next_node, cost));
      }
    }
  }
  priority_queue<State> que;
  que.push(State(0, V, false));
  for (int i = 0; i < 4400; i++){
    for (int j = 0; j < 2; j++){
      cost[i][j] = -100;
    }
  }
  cost[0][0] = V;
  while (!que.empty()){
    State pos = que.top();
    que.pop();

    if (cost[pos.node][pos.use] > pos.hp){
      continue;
    }
    //cout << pos.node << " " << pos.hp << endl;
    if (!pos.use and pos.node == gy * N + gx){
      pos.use = true;
      pos.hp *= 2;
    }
    if (pos.node == N * (N - 1) + (N - 1)){
      cout << "YES" << endl;
      return 0;
    }
    for (int i = 0; i < Edges[pos.node].size(); i++){
      Edge np = Edges[pos.node][i];
      if (pos.hp - np.cost > 0){
	if (cost[np.node][pos.use] < pos.hp - np.cost){
	  cost[np.node][pos.use] = pos.hp - np.cost;
	  que.push(State(np.node, cost[np.node][pos.use], pos.use));
	}
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
0