結果

問題 No.20 砂漠のオアシス
ユーザー hotpepsihotpepsi
提出日時 2015-03-26 17:53:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 451 ms / 5,000 ms
コード長 1,139 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 61,784 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:25:11
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstring>

using namespace std;

int N, V, Ox, Oy;
int L[256][256];
int visited[256][256];

int dfs(int x, int y, int v) {
  visited[y][x] = v;
  if (x == N-1 && y == N-1) {
    return 1;
  }
  const int dx[] = {-1,1,0,0};
  const int dy[] = {0,0,-1,1};
  for (int d = 0; d < 4; ++d) {
    int nx = x + dx[d], ny = y + dy[d];
    if (nx >= 0 && nx < N && ny >= 0 && ny < N) {
      int r = v - L[ny][nx];
      if (r > visited[ny][nx]) {
        if (dfs(nx, ny, r)) {
          return 1;
        }
      }
    }
  }
  return 0;
}

int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
  stringstream ss(s);
  ss >> N >> V >> Ox >> Oy;
  --Ox, --Oy;
  for (int i = 0; i < N; ++i) {
    getline(cin, s);
    stringstream ss(s);
    for (int j = 0; j < N; ++j) {
      ss >> L[i][j];
    }
  }
  int possible = dfs(0, 0, V);
  if (!possible) {
    int r = visited[Oy][Ox];
    if (!(Ox == 0 && Oy == 0) && r > 0) {
      memset(visited, 0, sizeof(visited));
      possible = dfs(Ox, Oy, r * 2);
    }
  }
  cout << (possible ? "YES" : "NO") << endl;
	return 0;
}
0