結果

問題 No.20 砂漠のオアシス
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-10 22:14:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 1,323 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 164,896 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 06:49:10
合計ジャッジ時間 2,613 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;


int done[200][200];
int L[200][200];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};

struct NODE{
	int x,y,c;
};
bool operator < (const NODE &a,const NODE &b){
	return a.c > b.c;
}
int main(){
	int N,V,Ox,Oy;
	cin >> N >> V >> Ox >> Oy;
	--Ox,--Oy;
	for(int i = 0 ; i < N ; i++)
		for(int j = 0 ; j < N ; j++)
			cin >> L[i][j];
	priority_queue<NODE> Q;
	
	int V2 = -1;
	Q.push({0,0,0});
	while( Q.size() ){
		auto q = Q.top(); Q.pop();
		if( done[q.y][q.x]++ ) continue;
		if( q.c >= V ) continue;
		if( q.y == N - 1 && q.x == N - 1 ){
			cout << "YES" << endl;
			return 0;
		}
		if( q.y == Oy && q.x == Ox ){
			V2 = max(V2,2*(V - q.c));
		}
		for(int i = 0 ; i < 4 ; i++){
			int tx = q.x + dx[i];
			int ty = q.y + dy[i];
			if( tx < 0 || tx >= N || ty >= N || ty < 0 ) continue;
			Q.push({tx,ty,q.c+L[ty][tx]});
		}
	}
	memset(done,0,sizeof(done));
	Q.push({Ox,Oy,0});
	while( Q.size() ){
		auto q = Q.top(); Q.pop();
		if( done[q.y][q.x]++ ) continue;
		if( q.c >= V2 ) continue;
		if( q.y == N - 1 && q.x == N - 1 ){
			cout << "YES" << endl;
			return 0;
		}
		for(int i = 0 ; i < 4 ; i++){
			int tx = q.x + dx[i];
			int ty = q.y + dy[i];
			if( tx < 0 || tx >= N || ty >= N || ty < 0 ) continue;
			Q.push({tx,ty,q.c+L[ty][tx]});
		}
	}
	cout << "NO" << endl;
	
}
0