結果

問題 No.20 砂漠のオアシス
ユーザー wait_sushiwait_sushi
提出日時 2020-01-29 16:03:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,355 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 176,596 KB
実行使用メモリ 26,948 KB
最終ジャッジ日時 2023-10-14 05:46:35
合計ジャッジ時間 3,350 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
18,620 KB
testcase_01 AC 12 ms
22,596 KB
testcase_02 AC 12 ms
22,384 KB
testcase_03 AC 10 ms
18,868 KB
testcase_04 AC 14 ms
22,672 KB
testcase_05 AC 46 ms
25,872 KB
testcase_06 AC 54 ms
26,900 KB
testcase_07 AC 54 ms
26,748 KB
testcase_08 AC 54 ms
26,596 KB
testcase_09 AC 55 ms
26,948 KB
testcase_10 WA -
testcase_11 AC 11 ms
22,436 KB
testcase_12 WA -
testcase_13 AC 14 ms
22,832 KB
testcase_14 AC 14 ms
23,060 KB
testcase_15 AC 13 ms
23,052 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 19 ms
23,528 KB
testcase_20 AC 12 ms
22,748 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;
};
vector<edge> G[MAX_N];
vl visited;

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

void resetv(void) { visited = vl(MAX_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;
	a=n;
	n=n*n;
	x--;
	y--;
	ll A[a][a];
	rep(i, a) {
		rep(j, a) {
			cin >> k;
			A[i][j] = k;
		}
	}

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

	vl B = Dijkstra(0);

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