結果
| 問題 | No.34 砂漠の行商人 | 
| コンテスト | |
| ユーザー |  kyuridenamida | 
| 提出日時 | 2016-02-11 10:37:36 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,323 bytes | 
| コンパイル時間 | 1,463 ms | 
| コンパイル使用メモリ | 165,908 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-22 00:22:12 | 
| 合計ジャッジ時間 | 2,578 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | WA * 26 | 
ソースコード
#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;
	
}
            
            
            
        