結果

問題 No.323 yuki国
ユーザー koyumeishi
提出日時 2015-12-16 09:35:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,479 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 93,416 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-28 12:21:50
合計ジャッジ時間 2,218 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <bitset>
using namespace std;

typedef bitset<2550> bits;

int main(){
	int h,w;
	cin >> h >> w;
	vector<int> a(2),r(2),c(2);
	for(int i=0; i<2; i++) cin >> a[i] >> r[i] >> c[i];
	vector<string> m(h);
	for(int i=0; i<h; i++) cin >> m[i];

	if( abs(a[0]-a[1])%2 != abs(r[0]-r[1] + c[0]-c[1])%2){
		cout << "No" << endl;
		return 0;
	}

	bits inc,dec;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			(m[i][j]=='.'?dec:inc).set( (w+1)*i + j );
		}
	}
	
	int mx_size = 1200;
	int times = 1200;
	
	vector<bits> s(mx_size);
	s[a[0]].set( (w+1)*r[0] + c[0] );

	queue<int> update;
	vector<int> used(mx_size, 0);
	update.push(a[0]);
	used[a[0]] = 1;	
	while(update.size() && s[a[1]][(w+1)*r[1] + c[1]]==false){
		int k = update.front();
		update.pop();
		used[k] = 0;

		bits tmp = (s[k]<<1) | (s[k]>>1) | (s[k]<<(w+1)) | (s[k]>>(w+1));
		if(k+1<mx_size){
			bits next = s[k+1]|(tmp&inc);
			if(next != s[k+1]){
				s[k+1] = next;
				if(used[k+1]==0){
					used[k+1] = 1;
					update.push(k+1);
				}
			}
		}
		
		if(k-1>0){
			bits next = s[k-1]|(tmp&dec);
			if(next != s[k-1]){
				s[k-1] = next;
				if(used[k-1]==0){
					used[k-1] = 1;
					update.push(k-1);
				}
			}
		}
	}
	
	if(s[a[1]][(w+1)*r[1] + c[1]]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}
0