結果

問題 No.323 yuki国
ユーザー chocorusk
提出日時 2018-12-21 16:59:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 361 ms / 5,000 ms
コード長 1,324 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 101,580 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-09-25 09:33:52
合計ジャッジ時間 5,993 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
int h, w;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
bool check(int x, int y){
  if(x<0 || x>=h || y<0 || y>=w) return false;
  return true;
}
int main()
{
	cin>>h>>w;
	int a, b, sx, sy, gx, gy;
	cin>>a>>sx>>sy;
	cin>>b>>gx>>gy;
	string m[50];
	for(int i=0; i<h; i++) cin>>m[i];
	queue<Pi> que;
	bool ok[50][50][4001]={};
	ok[sx][sy][a]=1; que.push({{sx, sy}, a});
	while(!que.empty()){
		Pi p=que.front(); que.pop();
		int x=p.first.first, y=p.first.second, t=p.second;
		for(int k=0; k<4; k++){
			int x1=x+dx[k], y1=y+dy[k];
			if(!check(x1, y1)) continue;
			if(m[x1][y1]=='.'){
				if(t==1) continue;
				if(ok[x1][y1][t-1]) continue;
				ok[x1][y1][t-1]=1;
				que.push({{x1, y1}, t-1});
			}else{
				if(t>=4000) continue;
				if(ok[x1][y1][t+1]) continue;
				ok[x1][y1][t+1]=1;
				que.push({{x1, y1}, t+1});
			}
		}
	}
	if(ok[gx][gy][b]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}
0