結果

問題 No.20 砂漠のオアシス
ユーザー こるこる
提出日時 2017-02-17 11:25:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,905 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 73,732 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 07:04:05
合計ジャッジ時間 1,551 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
#define ll long long
#define PLL pair<ll,ll>
#define VS vector<string>
#define VL vector<ll>
#define rep(i,a) for (ll i=0;i<a;i++)
#define nrep(i,n,a) for (ll i=n;i<a;i++)
#define INF 1145141919810
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define TS(n) to_string(n)

using namespace std;

struct NODE {
	ll level, dist ,x ,y;
};

bool operator< (const NODE &node1, const NODE &node2) { return node1.dist < node2.dist; }
bool operator> (const NODE &node1, const NODE &node2) { return node1.dist > node2.dist; }

NODE nodes[202][202];
bool flag[202][202];

void update(priority_queue<NODE ,vector<NODE> ,greater<NODE> > &pq,NODE node,ll x, ll y) {
	//cout << "update:" << x << " " << y << flag[x][y]<<endl;
	if (nodes[x][y].dist == -1 || nodes[x][y].dist > node.dist + nodes[x][y].level) {
		nodes[x][y].dist = nodes[x][y].level + node.dist;
		if (!flag[x][y]) {
			//cout << "yala" << endl;
			flag[x][y] = true;
			pq.push(nodes[x][y]);
			//cout << "update_pq_size=" << pq.size() << endl;
		}
	}
}

int main() {
	ll N, V, Ox, Oy;
	cin >> N >>V >> Ox >> Oy;
	rep(i, N) rep(j, N) {
		cin >> nodes[i][j].level;
		nodes[i][j].dist = -1;
		nodes[i][j].x = i; nodes[i][j].y = j; flag[i][j] = false;
	}
	ll cost;
	priority_queue<NODE,vector<NODE> ,greater<NODE> > pq;
	nodes[0][0].dist = 0;
	pq.push(nodes[0][0]);
	NODE node;
	while(!pq.empty()) {
		node = pq.top(); pq.pop();
		//cout << node.x << " " << node.y << endl;
		flag[node.x][node.y] = false;
		if (node.x > 0) { update(pq,node, node.x - 1, node.y); }
		if (node.x < N-1) { update(pq,node, node.x + 1, node.y); }
		if (node.y > 0) { update(pq,node, node.x, node.y - 1); }
		if (node.y < N-1) { update(pq,node, node.x, node.y + 1); }
		//cout << "main_pq_size=" << pq.size() << endl;
	}ll start_to_end = V - nodes[N - 1][N - 1].dist;
	if (start_to_end > 0){
		cout << "YES" << endl;
	}
	else if (Ox ==0 && Oy == 0){
		cout << "NO" << endl;
	}
	else{
		ll start_to_O = V - nodes[Ox - 1][Oy - 1].dist;
		if (start_to_O <= 0){
			cout << "NO" << endl;
			exit(0);
		}start_to_O *= 2;
		rep(i, N) rep(j, N) nodes[i][j].dist = -1;
		nodes[Ox - 1][Oy - 1].dist = 0;
		pq.push(nodes[Ox - 1][Oy - 1]);
		while (!pq.empty()) {
			node = pq.top(); pq.pop();
			//cout << node.x << " " << node.y << endl;
			flag[node.x][node.y] = false;
			if (node.x > 0) { update(pq, node, node.x - 1, node.y); }
			if (node.x < N - 1) { update(pq, node, node.x + 1, node.y); }
			if (node.y > 0) { update(pq, node, node.x, node.y - 1); }
			if (node.y < N - 1) { update(pq, node, node.x, node.y + 1); }
			//cout << "main_pq_size=" << pq.size() << endl;
		}ll O_to_end = start_to_O - nodes[N - 1][N - 1].dist;
		cout << (O_to_end > 0 ? "YES" : "NO") << endl;
	}
	return 0;
}
0