結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  Pulmn | 
| 提出日時 | 2018-07-24 18:31:22 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 35 ms / 5,000 ms | 
| コード長 | 1,578 bytes | 
| コンパイル時間 | 1,465 ms | 
| コンパイル使用メモリ | 172,268 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-23 09:45:01 | 
| 合計ジャッジ時間 | 2,477 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 | 
ソースコード
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-18;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
class Graph{
	private:
	int n;
	vvp g;
	public:
	int DIJ(int s,int t){
		priority_queue<P> q;
		vi d(n,inf);
		d[s]=0;
		q.push({0,s});
		while(!q.empty()){
			P p=q.top();
			q.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				int u=i.first,D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d[t];
	}
	Graph(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){
		g[s].push_back({t,c});
	}
};
int n,m,x,y;
vvi a;
int main(){
	cin>>n>>m>>y>>x;
	x--;y--;
	a=vvi(n,vi(n));
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	Graph g(n*n);
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int k=0;k<4;k++){
		int X=i+dx[k],Y=j+dy[k];
		if(X>=0&&X<n&&Y>=0&&Y<n) g.add_edge(i*n+j,X*n+Y,a[X][Y]);
	}
	if(m>g.DIJ(0,n*n-1)||x>=0&&(m-g.DIJ(0,x*n+y))*2>g.DIJ(x*n+y,n*n-1)) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}
            
            
            
        