結果

問題 No.20 砂漠のオアシス
ユーザー togari_takamototogari_takamoto
提出日時 2016-02-25 22:18:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,814 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 173,912 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-21 06:49:36
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 22 ms
7,552 KB
testcase_06 AC 28 ms
8,192 KB
testcase_07 AC 27 ms
8,192 KB
testcase_08 AC 28 ms
8,192 KB
testcase_09 AC 32 ms
8,192 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 7 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;

#define REP(i,n) for(ll i=0; i<(n); ++i)
#define FOR(i,b,n) for(ll i=(b); i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define TEN(x) ((ll)1e##x)

typedef ll Id;
typedef ll Distance;
#define INF_DIST numeric_limits<Distance>::max()
struct Edge{Id to; Distance cost;};
typedef vector<vector<Edge>> Graph;
vector<Distance> dijkstra(Id s, const Graph & g){
    vector<Distance> d(g.size(), INF_DIST);
    d[s] = 0;
    
    typedef pair<Distance, Id> P;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top(); que.pop();
        Id v = p.second;
        if(d[v] < p.first) continue;
        for (Edge e : g[v]) if(d[e.to] > d[v] + e.cost){
            d[e.to] = d[v] + e.cost;
            que.push(P(d[e.to], e.to));
        }
    }

    return d;
}

ll dx[] = { -1, 0, 1, 0 };
ll dy[] = { 0, -1, 0, 1 };
bool contain(ll x, ll max_x) { return 0 <= x && x < max_x; }

int main() {
	ll n, v, ox, oy;
	cin >> n >> v >> ox >> oy;
	vvl field(n, vl(n));
	REP(i, n) REP(j, n) cin >> field[i][j];

	Graph g(n*n);
	REP(i, n) REP(j, n) {
		REP(d, 4) if (contain(i + dx[d], n) && contain(j + dy[d], n)) {
			g[i*n + j].push_back({ (i + dx[d])*n + (j + dy[d]), field[i + dx[d]][j + dy[d]] });
		}
	}

	auto dist = dijkstra(0, g);
	if (dist[n*n - 1] < v) {
		cout << "YES" << endl;
	}else if (ox != 0) {
		v -= dist[(ox-1)*n + oy-1]; v *= 2;
		dist = dijkstra((ox-1)*n+oy-1, g);
		cout << (dist[n*n - 1] < v ? "YES" : "NO") << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}
0