結果

問題 No.20 砂漠のオアシス
ユーザー yuustiyuusti
提出日時 2014-12-06 03:31:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 1,999 bytes
コンパイル時間 1,341 ms
コンパイル使用メモリ 98,300 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 07:22:39
合計ジャッジ時間 2,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int N = 210;
int dd[2][N][N];
int L[N][N];

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

int n;

void dijk(int sx, int sy, int k){

	int (*dist)[N] = dd[k];
	rep(i, N) rep(j, N) dist[i][j] = 1e9;
	dist[sy][sx] = 0;

	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> q;
	q.push(MT(0, sx, sy));

	while (!q.empty()){
		auto t = q.top();
		q.pop();

		int d, x, y;
		tie(d, x, y) = t;
		if (dist[y][x] < d) continue;

		rep(dir, 4){
			int nx = x + dx[dir], ny = y + dy[dir];
			if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
			int nd = d + (!k?L[ny][nx]:L[y][x]);
			if (dist[ny][nx] <= nd) continue;
			dist[ny][nx] = nd;
			q.push(MT(nd, nx, ny));
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int v, ox, oy;
	cin >> n >> v >> ox >> oy;

	rep(i, n) rep(j, n) cin >> L[i][j];

	--ox, --oy;
	dijk(0, 0, 0);
	dijk(n - 1, n - 1, 1);

	bool b = dd[0][n - 1][n - 1] < v;

	if (ox >= 0 && oy >= 0){
		int x = v - dd[0][oy][ox];
		if (x >= 0 && x * 2 > dd[1][oy][ox]) b = true;
	}

	cout << (b ? "YES":"NO") << endl;

	
	return 0;
}
0