結果

問題 No.34 砂漠の行商人
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-11 10:37:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 1,239 ms
コンパイル使用メモリ 166,012 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 22:54:00
合計ジャッジ時間 2,301 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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