結果

問題 No.157 2つの空洞
ユーザー tails
提出日時 2015-02-27 00:10:57
言語 Perl
(5.40.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-23 21:51:22
合計ジャッジ時間 969 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

($w,$h)=<>=~/\d+/g;
$/=\1;
for$y(1..$h){
    for$x(1..$w+1){
	$f{$x,$y}=<>;
    }
}
l1:{
    for$y(1..$h){
	for$x(1..$w){
	    if($f{$x,$y}eq'.'){
		$f{$x,$y}=A;
		last l1;
	    }
	}
    }
}
for(0..99){
for$y(1..$h){
    for$x(1..$w){
	if($f{$x,$y}eq'.'){
	    if($f{$x-1,$y}eq A || $f{$x+1,$y}eq A || $f{$x,$y-1}eq A || $f{$x,$y+1}eq A ){
		$f{$x,$y}=A;
	    }
	}
    }
}
}
for$l(0..99){
    for$y(1..$h){
	for$x(1..$w){
	    if($f{$x,$y}eq 'A'){
		if($f{$x-1,$y}eq '.'|| $f{$x+1,$y}eq '.' || $f{$x,$y-1}eq '.' || $f{$x,$y+1}eq '.' ){
		    print $l;
		    exit;
		}
		if($f{$x-1,$y}eq'#'){
		    $f{$x-1,$y}=B;
		}
		if($f{$x+1,$y}eq'#'){
		    $f{$x+1,$y}=B;
		}
		if($f{$x,$y-1}eq'#'){
		    $f{$x,$y-1}=B;
		}
		if($f{$x,$y+1}eq'#'){
		    $f{$x,$y+1}=B;
		}
	    }
	}
    }
    for$y(1..$h){
	for$x(1..$w){
	    if($f{$x,$y}eq B){
		$f{$x,$y}=A;
	    }
	}
    }
}
0