結果

問題 No.323 yuki国
ユーザー koyumeishikoyumeishi
提出日時 2015-12-16 09:35:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 1,479 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 88,316 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 21:17:58
合計ジャッジ時間 2,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 56 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 36 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 52 ms
4,380 KB
testcase_17 AC 16 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 44 ms
4,380 KB
testcase_29 AC 45 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 6 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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