結果

問題 No.20 砂漠のオアシス
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-13 13:33:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,660 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 69,720 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:55:41
合計ジャッジ時間 1,468 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e8;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int n, v, ox, oy;
int cost[210][210];//dist[i][j] i->jのコスト
int dist[210][210];//距離

void diskstra(int y, int x){
	rep(i, n)rep(j, n)dist[i][j] = INF;
	//<cost, (座標)>
	priority_queue<P, vector<PP>, greater<PP> > 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;
		// printf("%d %d %d\n", c, now.first, now.second);
		que.pop();
		// printf("%d %d %d\n", now.first, now.second, c);

		// if(dist[now.first][now.second] != INF) continue;
		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;
			// printf("dist[%d][%d] = %d\n", ny, nx, dist[ny][nx]);
			dist[ny][nx] = c + cost[ny][nx];
			que.push(make_pair(dist[ny][nx], make_pair(ny, nx)));
		}
	}
}

int main(void){
	cin >> n >> v >> ox >> oy;
	ox--; oy--;
	rep(i, n)rep(j, n) cin >> cost[i][j];
	diskstra(0, 0);
	// printf("%d\n", dist[n - 1][n - 1]);
	if(dist[n - 1][n - 1] < v){
		printf("YES\n"); return 0;
	}
	if(ox == -1 && oy == -1){
		printf("NO\n"); return 0;
	}
	// printf("k\n");
	int t = (v - dist[oy][ox]) * 2; //2倍
	diskstra(oy, ox);
	if(t - dist[n - 1][n - 1] > 0){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}
0