結果

問題 No.20 砂漠のオアシス
ユーザー PulmnPulmn
提出日時 2018-07-24 18:31:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 1,578 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 157,212 KB
実行使用メモリ 6,316 KB
最終ジャッジ日時 2023-09-05 14:03:35
合計ジャッジ時間 2,568 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 26 ms
5,928 KB
testcase_06 AC 35 ms
6,096 KB
testcase_07 AC 36 ms
6,136 KB
testcase_08 AC 35 ms
6,316 KB
testcase_09 AC 36 ms
6,224 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0