結果

問題 No.20 砂漠のオアシス
ユーザー y_mazuny_mazun
提出日時 2015-04-24 21:15:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 1,487 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 55,496 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 07:29:58
合計ジャッジ時間 1,883 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int dp[200][200][2];

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

int main(){
  const int n = getInt();
  const int v = getInt();
  const int ox = getInt() - 1;
  const int oy = getInt() - 1;

  vector<vector<int> > g(n, vector<int>(n));

  REP(i,n) REP(j,n)
    g[i][j] = getInt();

  typedef pair<int, pair<pair<int, int>, int> > data;
  priority_queue<data> pq;

  auto cd = [](int hp, int x, int y, int o){
    return data(hp, make_pair(make_pair(x, y), o));
  };

  pq.push(cd(v, 0, 0, 0));

  while(pq.size()){
    const data d = pq.top(); pq.pop();

    const int h = d.first;
    const int x = d.second.first.first;
    const int y = d.second.first.second;
    const int o = d.second.second;

    if(dp[y][x][o]) continue;
    dp[y][x][o] = h;

    if(x == n - 1 && y == n - 1){
      puts("YES");
      return 0;
    }

    REP(i,4){
      const int xx = x + _dx[i];
      const int yy = y + _dy[i];

      if(ISIN(xx, yy, n, n)){
	const int hh = h * (ox == x && oy == y && o == 0 ? 2 : 1) - g[yy][xx];
	const int oo = ox == x && oy == y ? 1 : o;

	if(dp[yy][xx][oo] != 0) continue;
	if(hh <= 0) continue;
	pq.push(cd(hh, xx, yy, oo));
      }
    }
  }

  puts("NO");

  return 0;
}
0