結果

問題 No.20 砂漠のオアシス
ユーザー wait_sushiwait_sushi
提出日時 2020-01-29 23:27:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,474 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 179,960 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2023-10-14 07:58:33
合計ジャッジ時間 3,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 31 ms
8,348 KB
testcase_06 AC 39 ms
8,832 KB
testcase_07 AC 38 ms
8,692 KB
testcase_08 AC 38 ms
8,532 KB
testcase_09 AC 37 ms
8,764 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 5 ms
4,352 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if (flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct edge {
	ll to, cost;
};
struct Gragh {
	ll N;
	vector<vector<edge>> G;
	vl visited;

	Gragh(ll n) {
		N = n;
		G.resize(N);
		resetv();
	}

	void add(ll a, ll b, ll c = 1) { G[a].push_back((edge) { b, c }); }

	void resetv(void) { visited = vl(N, 0); }

	vl Dijkstra(ll r) {
		vl cost(N, INF);
		resetv();
		priority_queue<PP, vector<PP>, greater<PP>> pq;
		ll a, b = r;
		cost[b] = 0;
		visited[b] = 1;

		for (edge i : G[b]) {
			if (cost[b] + i.cost < cost[i.to]) {
				pq.push(make_pair(cost[b] + i.cost, i.to));
			}
		}
		while (!pq.empty()) {
			a = pq.top().first;
			b = pq.top().second;
			pq.pop();
			if (visited[b] == 1)continue;
			visited[b] = 1;
			cost[b] = a;
			for (edge i : G[b]) {
				if (cost[b] + i.cost < cost[i.to]) {
					pq.push(make_pair(cost[b] + i.cost, i.to));
				}
			}
		}

		return cost;
	}
};
int main() {
    cin >> n;
	cin >> h >> x >> y;
	Gragh G(n*n);
	x--;
	y--;
	ll A[n][n];
	rep(i, n) {
		rep(j, n) {
			cin >> k;
			A[i][j] = k;
		}
	}

	rep(i, n) {
		rep(j, n) {
			if (i > 0)G.add(i * n + j, (i - 1) * n + j, A[i - 1][j]);
			if (i < n - 1)G.add(i * n + j, (i + 1) * n + j, A[i + 1][j]);
			if (j > 0)G.add(i * n + j, i * n + j - 1, A[i][j - 1]);
			if (j < n - 1)G.add(i * n + j, i * n + j + 1, A[i][j + 1]);
		}
	}

	vl B = G.Dijkstra(0);

	if (x > -1){
		vl C = G.Dijkstra(x * n + y);
		ans = max(h - B[n * n - 1], (h - B[x * n + y]) * 2 - C[n * n - 1]);
	}
	else ans = h - B[n * n - 1];
	if (ans > 0)cout << "YES" << endl;
	else cout << "NO" << endl;
}
0