結果

問題 No.20 砂漠のオアシス
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-09 00:37:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,532 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 164,708 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:24:47
合計ジャッジ時間 2,027 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 8 ms
6,940 KB
testcase_06 AC 7 ms
6,944 KB
testcase_07 AC 30 ms
6,940 KB
testcase_08 AC 10 ms
6,944 KB
testcase_09 AC 25 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 1 ms
6,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, 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;
}
0