結果

問題 No.20 砂漠のオアシス
ユーザー IL_mstaIL_msta
提出日時 2015-07-15 18:16:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,106 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 93,100 KB
実行使用メモリ 44,476 KB
最終ジャッジ日時 2024-04-21 06:37:38
合計ジャッジ時間 7,426 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
44,476 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 20 ms
6,940 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
const int V = 160000,INF = 1<<28;
int dist[200][200];
bool use[200][200];
int dist2[200][200];
bool use2[200][200];

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(10);//
	int N,V,Ox,Oy;
	cin>>N>>V>>Ox>>Oy;
	--Ox;
	--Oy;
	int L[200][200];
	rep(i,N)rep(j,N){
		cin>>L[i][j];//y,x
	}
	int dx[4] = { 1, 0,-1, 0};
	int dy[4] = { 0, 1, 0,-1};
	int px,py,nx,ny;

	rep(i,200)rep(j,200){
		dist[i][j] = INF;
		dist2[i][j] = INF;
	}
	
	priority_queue<PII, vector<PII>,greater<PII> > q;
	PII temp;

	q.push( PII(0,0) );
	
	while( !q.empty() ){
		temp = q.top();q.pop();
		py = (temp.second/N);
		px = (temp.second%N);
		if( use[py][px] == true) continue;
		use[py][px] = true;
		dist[py][px] = temp.first;
		rep(i,4){
			ny = py + dy[i];
			nx = px + dx[i];
			if(0 <= ny && ny < N && 0 <= nx && nx < N && use[ny][nx] == false){
				q.push( PII(temp.first + L[ny][nx], ny*N+nx) );
			}
		}
	}

	if(dist[N-1][N-1] < V){
		P("YES");
		return 0;
	}

	if(Ox != -1 || Oy != -1)
	{
	
	rep(i,N)rep(j,N)use[i][j] = false;
	
	q.push( PII(0,Oy*N+Ox) );
	while( !q.empty() ){
		temp = q.top();q.pop();
		py = (temp.second/N);
		px = (temp.second%N);
		if( use[py][px] == true) continue;
		use2[py][px] = true;
		dist2[py][px] = temp.first;
		rep(i,4){
			ny = py + dy[i];
			nx = px + dx[i];
			if(0 <= ny && ny < N && 0 <= nx && nx < N && use2[ny][nx] == false){
				q.push( PII(temp.first + L[ny][nx], ny*N+nx) );
			}
		}
	}
	}

	
	if( dist[Oy][Ox] < V && dist2[N-1][N-1] < (V-dist[Oy][Ox])*2 ){
		P("YES");
	}
	else{
		P("NO");
	}
    return 0;
}
0