結果

問題 No.20 砂漠のオアシス
ユーザー kenken714kenken714
提出日時 2019-04-19 17:55:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 1,754 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 91,160 KB
実行使用メモリ 9,900 KB
最終ジャッジ日時 2023-10-23 17:44:22
合計ジャッジ時間 2,398 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,268 KB
testcase_01 AC 3 ms
6,276 KB
testcase_02 AC 3 ms
6,276 KB
testcase_03 AC 4 ms
6,476 KB
testcase_04 AC 5 ms
6,484 KB
testcase_05 AC 27 ms
9,272 KB
testcase_06 AC 32 ms
9,888 KB
testcase_07 AC 33 ms
9,900 KB
testcase_08 AC 34 ms
9,900 KB
testcase_09 AC 32 ms
9,900 KB
testcase_10 AC 3 ms
6,268 KB
testcase_11 AC 3 ms
6,268 KB
testcase_12 AC 4 ms
6,412 KB
testcase_13 AC 4 ms
6,448 KB
testcase_14 AC 5 ms
6,600 KB
testcase_15 AC 5 ms
6,512 KB
testcase_16 AC 8 ms
6,980 KB
testcase_17 AC 7 ms
6,764 KB
testcase_18 AC 8 ms
6,876 KB
testcase_19 AC 9 ms
7,000 KB
testcase_20 AC 4 ms
6,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, v, ox, oy, o, s[110000];
ll d[110000]; // 結果
bool ok = false;
struct edge { ll to, cost; };
vector<edge> g[110000]; //隣接リスト to, cost
void dijkstra(ll a) {
	priority_queue<P, vector<P>, greater<P> > q;
	fill(d, d + n * n, INF);
	d[a] = 0;
	q.push(P(0, a));
	while (!q.empty()) {
		P p = q.top();
		q.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		REP(i, g[v].size()) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}
ll v1[4] = { 0,0,1,-1 }, v2[4] = { 1,-1,0,0 };
int main() {
	cin >> n >> v >> ox >> oy;
	ox--;
	oy--;
	o = oy * n + ox;
	REP(i, n) {
		REP(j, n) {
			cin >> s[i * n + j];
		}
	}
	REP(i, n) {
		REP(j, n) {
			REP(k, 4) {
				if ((j == n - 1 and v2[k] == 1) or (j == 0 and v2[k] == -1))continue;
				ll now = i * n + j + v1[k] * n + v2[k];
				if (now < 0 or now >= n * n)continue;
				g[i * n + j].push_back({ now, s[now] });
			}
		}
	}
	dijkstra(0);
	if (d[n * n - 1] < v)ok = true;
	if (o >= 0) {
		v = (v - d[o]) * 2;
		dijkstra(o);
		if (d[n * n - 1] < v)ok = true;
	}
	cout << (ok ? "YES" : "NO") << endl;
}



0