結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 19 ms
5,376 KB
testcase_07 AC 21 ms
5,376 KB
testcase_08 AC 19 ms
5,376 KB
testcase_09 AC 19 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 2 ms
5,376 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[210][210];
bool flag[210][210];
*/

ll dist[210][210];
ll cost[210][210];
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
ll N, V, Ox, Oy;

void diskstra(int y, int x){
	rep(i, N) rep(j, N) dist[i][j] = INF;
	//<cost, (座標)>
	priority_queue<PLL, vector<pair<ll,PLL> >, greater<pair<ll,PLL> > > que;
	que.push(make_pair(0, make_pair(y, x)));
	dist[y][x] = 0;
	while (!que.empty()){
		auto c = que.top().first;
		auto now = que.top().second;
		que.pop();

		// if(dist[now.first][now.second] < c) continue;
		rep(i, 4){
			int ny = now.first + dy[i], nx = now.second + dx[i];
			if (!(0 <= ny && ny < N && 0 <= nx && nx < N)) continue;
			if (dist[ny][nx] <= c + cost[ny][nx]) continue;
			dist[ny][nx] = c + cost[ny][nx];
			que.push(make_pair(dist[ny][nx], make_pair(ny, nx)));
		}
	}
}

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

int main() {
	
	cin >> N >> V >> Ox >> Oy;
	rep(i, N) rep(j, N) {
		/*
		cin >> nodes[i][j].level;
		nodes[i][j].dist = INF;
		nodes[i][j].x = i; nodes[i][j].y = j; flag[i][j] = false;
		*/
		cin >> cost[i][j];
	}
	/*
	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 (nodes[N-1][N-1].dist<V){
		cout << "YES" << endl;
		return 0;
	}
	if (Ox == 0 && Oy == 0){
		cout << "NO" << endl;
		return 0;
	}
	ll start_to_O = (V - nodes[Ox - 1][Oy - 1].dist)*2;

	rep(i, N) rep(j, N) nodes[i][j].dist = INF;
	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;
	}
	if (nodes[N-1][N-1].dist<start_to_O){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	*/

	diskstra(0, 0);

	if (dist[N - 1][N - 1] < V){
		cout << "YES" << endl;
		return 0;
	}
	if (Oy == 0 && Ox == 0){
		cout << "NO" << endl;
		return 0;
	}
	ll start_to_O = (V - dist[Ox - 1][Oy - 1]) * 2;
	diskstra(Ox - 1, Oy - 1);
	if (start_to_O > dist[N - 1][N - 1]){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}
0