結果

問題 No.20 砂漠のオアシス
ユーザー ゆぽゆぽ
提出日時 2016-05-13 23:52:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 1,933 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 94,460 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:53:10
合計ジャッジ時間 1,584 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 19 ms
6,944 KB
testcase_06 AC 20 ms
6,940 KB
testcase_07 AC 20 ms
6,940 KB
testcase_08 AC 14 ms
6,940 KB
testcase_09 AC 19 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 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 3 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 5 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define INF (1000000)

int N, V, Ox, Oy;
int L[202][202];

int c[202][202], d[202][202];

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

int ar[4][2] = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } };

void wf(int a[202][202], int sx, int sy) {
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(MP(0, MP(sx, sy)));
	while (!q.empty()) {
		P t = q.top(); q.pop();
		int v = t.first, x = t.second.first, y = t.second.second;
		REP(i, 4) {
			int ax = x + ar[i][0], ay = y + ar[i][1];
			if (a[ax][ay] > v + L[ax][ay]) {
				a[ax][ay] = v + L[ax][ay];
				q.push(MP(a[ax][ay], MP(ax, ay)));
			}
		}
	}
}

int main(int argc, char **argv) {
	cin >> N >> V >> Ox >> Oy;
	FOR(y, 1, N + 1) FOR(x, 1, N + 1) {
		cin >> L[x][y];
		c[x][y] = d[x][y] = INF;
	}
	REP(i, N + 2) {
		L[i][0] = L[i][N + 1] = L[0][i] = L[N + 1][i] = INF;
		c[i][0] = c[i][N + 1] = c[0][i] = c[N + 1][i] = -1;
		d[i][0] = d[i][N + 1] = d[0][i] = d[N + 1][i] = -1;
	}
	wf(c, 1, 1);
	bool res = c[N][N] < V;
	if (!res && c[Ox][Oy] < V) {
		wf(d, Ox, Oy);
		res = d[N][N] < (V - c[Ox][Oy]) * 2;
	}
	cout << (res ? "YES" : "NO") << endl;
	return 0;
}
0