結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  purple_jwl | 
| 提出日時 | 2015-03-09 00:37:11 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 33 ms / 5,000 ms | 
| コード長 | 1,532 bytes | 
| コンパイル時間 | 1,410 ms | 
| コンパイル使用メモリ | 164,856 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:04:18 | 
| 合計ジャッジ時間 | 2,247 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 | 
ソースコード
#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, oFlg;
  State(int x, int y, int o): x(x), y(y), oFlg(o) {}
};
int N, V, ox, oy;
int L[200][200];
int maxV[200][200][2];
string solve() {
  memset(maxV, -1, sizeof(maxV));
  queue<State> Q;
  Q.push(State(0, 0, 0));
  maxV[0][0][0] = V;
  
  while(!Q.empty()) {
    State stt = Q.front();
    Q.pop();
    rep(i, 4) {
      int nx = stt.x + dx[i];
      int ny = stt.y + dy[i];
      if(!(0 <= nx && nx < N && 0 <= ny && ny < N)) continue;
      int v = maxV[stt.y][stt.x][stt.oFlg] - L[ny][nx];
      if(v <= 0) continue;
      if(nx == N - 1 && ny == N - 1) return "YES";
      
      if(maxV[ny][nx][stt.oFlg] < v) {
        maxV[ny][nx][stt.oFlg] = v;
        Q.push(State(nx, ny, stt.oFlg));
      }
      if(nx == ox && ny == oy && stt.oFlg == 0) {
        if(maxV[ny][nx][1] < v * 2) {
          maxV[ny][nx][1] = v * 2;
          Q.push(State(nx, ny, 1));
        }
      }
    }
  }
  return "NO";
}
int main() {
  // ios_base::sync_with_stdio(false);
  cin >> N >> V >> ox >> oy;
  ox--;
  oy--;
  rep(i, N) rep(j, N) cin >> L[i][j];
  cout << solve() << endl;
  return 0;
}
            
            
            
        