結果

問題 No.20 砂漠のオアシス
ユーザー A8pfA8pf
提出日時 2018-10-09 12:05:12
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,368 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 76,904 KB
実行使用メモリ 814,408 KB
最終ジャッジ日時 2023-08-02 18:56:02
合計ジャッジ時間 4,520 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
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 #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <queue>
#include <tuple>
using namespace std;
typedef tuple<int,int,int> T;
typedef long long ll;
ll MOD = 1e9+7;
int l[200][200];
bool f[200][200];
int main()
{
	int n,v,ox,oy;
	deque<T> q;//現在の座標x,y、残りレベルl
	int ans=0;
	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];
	}
	fill(f[0],f[200],false);
	//ここからBFS
	q.push_back(make_tuple(0,0,v));
	while(!q.empty())
	{
		T t=q.front();q.pop_front();
		int x=get<0>(t);
		int y=get<1>(t);
		int zan=get<2>(t);
		f[x][y]=true;
		//ゴールまでたどり着いた場合
		if(x==n-1 && y==n-1)
		{
			cout<<"YES"<<endl;
			return 0;
		}
		//上下左右調べる
		if(y>0 && !f[x][y-1])
		{
			int z=zan-l[x][y-1];
			if(y-1==oy && x==ox)
				z*=2;
			if(z>=0)
				q.push_back(T(x,y-1,z));
		}
		if(y<n-1 && !f[x][y+1])
		{
			int z=zan-l[x][y+1];
			if(y+1==oy && x==ox)
				z*=2;
			if(z>=0)
				q.push_back(T(x,y+1,z));
		}
		if(x>0 && !f[x-1][y])
		{
			int z=zan-l[x-1][y];
			if(y==oy && x-1==ox)
				z*=2;
			if(z>=0)
				q.push_back(T(x-1,y,z));
		}
		if(x<n-1 && !f[x+1][y])
		{
			int z=zan-l[x+1][y];
			if(y==oy && x+1==ox)
				z*=2;
			if(z>=0)
				q.push_back(T(x+1,y,z));
		}
	}
	cout<<"NO"<<endl;
	return 0;
}
0