結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  tkzw_21 | 
| 提出日時 | 2015-03-09 23:35:54 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,811 bytes | 
| コンパイル時間 | 1,595 ms | 
| コンパイル使用メモリ | 175,252 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:04:23 | 
| 合計ジャッジ時間 | 2,437 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 WA * 1 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
typedef long long ll;
const double EPS = 1e-8;
const int INF = 1e9;
const int MOD = 1e9+7;
int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
bool bfs(int V,int ox,int oy,vector<vector<int>>L){
	priority_queue<PP,vector<PP>,greater<PP>> pq;
	pq.push(make_pair(0,P(0,0)));
	int n = L.size();
	vector<vector<bool>>used(n,vector<bool>(n));
	int StoO=0,StoG=0;
	while(!pq.empty()){
		PP pp = pq.top();pq.pop();
		int x = pp.second.first;
		int y = pp.second.second;
		int d = pp.first;
		if(x == ox && y == oy)StoO = d;
		if(x == n-1 && y == n-1)StoG = d;
		for(int i=0;i<4;i++){
			int nx = x + dx[i],ny = y + dy[i];
			if(nx < 0 || ny < 0 || nx >= n || ny >= n)continue;
			if(used[ny][nx])continue;
			used[ny][nx] = true;
			pq.push(make_pair(d+L[ny][nx],P(nx,ny)));
		}
	}
	pq.push(make_pair(0,P(ox,oy)));
	vector<vector<bool>>used2(n,vector<bool>(n));
	int OtoG=0;
	while(!pq.empty()){
		PP pp = pq.top();pq.pop();
		int x = pp.second.first;
		int y = pp.second.second;
		int d = pp.first;
		if(x == n-1 && y == n-1)OtoG = d;
		for(int i=0;i<4;i++){
			int nx = x + dx[i],ny = y + dy[i];
			if(nx < 0 || ny < 0 || nx >= n || ny >= n)continue;
			if(used2[ny][nx])continue;
			used2[ny][nx] = true;
			pq.push(make_pair(d+L[ny][nx],P(nx,ny)));
		}
	}
	//cout << StoG << " " << StoO << " " << OtoG << endl;
	if(StoG < V)return true;
	if(ox+oy!=0 && V-StoO > 0){
		V = (V-StoO)*2;
		if(OtoG < V)return true;
	}
	return false;
}
int main(void) {
	int n,v,ox,oy;
	cin >> n >> v >> ox >> oy;
	ox--;oy--;
	vector<vector<int>>L(n,vector<int>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> L[i][j];
		}
	}
	if(bfs(v,ox,oy,L))cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}
            
            
            
        