結果

問題 No.602 隠されていたゲーム2
ユーザー tailstails
提出日時 2017-12-02 00:54:18
言語 Perl
(5.38.2)
結果
AC  
実行時間 563 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 34,608 KB
最終ジャッジ日時 2023-08-22 05:34:17
合計ジャッジ時間 4,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,184 KB
testcase_01 AC 6 ms
5,216 KB
testcase_02 AC 7 ms
5,344 KB
testcase_03 AC 6 ms
5,292 KB
testcase_04 AC 7 ms
5,088 KB
testcase_05 AC 6 ms
5,216 KB
testcase_06 AC 6 ms
5,108 KB
testcase_07 AC 7 ms
5,232 KB
testcase_08 AC 6 ms
5,348 KB
testcase_09 AC 6 ms
5,180 KB
testcase_10 AC 6 ms
5,184 KB
testcase_11 AC 6 ms
5,072 KB
testcase_12 AC 6 ms
5,252 KB
testcase_13 AC 6 ms
5,152 KB
testcase_14 AC 6 ms
5,284 KB
testcase_15 AC 6 ms
5,352 KB
testcase_16 AC 72 ms
8,880 KB
testcase_17 AC 157 ms
13,260 KB
testcase_18 AC 333 ms
26,772 KB
testcase_19 AC 563 ms
31,832 KB
testcase_20 AC 463 ms
32,328 KB
testcase_21 AC 461 ms
34,608 KB
testcase_22 AC 413 ms
31,892 KB
testcase_23 AC 306 ms
32,020 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

<>;
@d=sort{$b-$a}glob<>;
($x,$y)=glob<>;

if($x==0&&$y==0){
	print 0;
	exit;
}

$z=abs($x)+abs($y);
if(grep$z==$_,@d){
	print 1;
	exit;
}

($d0)=@d0=grep{$_%2==0}@d;
($d1)=@d1=grep{$_%2==1}@d;

if( $z%2 ) {
	if( grep{$z0=abs$z-$_;$z1=$z+$_;bs(0,@d0-1)}@d1 ) {
		print 2;
		exit;
	}
} else {
	if( $z<=$d0*2 || $z<=$d1*2 ) {
		print 2;
		exit;
	}
}

print -1;

sub bs {
	my($i1,$i2)=@_;
	while(1){
		if($i1>$i2){
			return 0;
		}
		my$i3=$i1+$i2>>1;
		if($d0[$i3]>$z1){
			$i1=$i3+1;
		}elsif($d0[$i3]<$z0){
			$i2=$i3-1;
		}else {
			return 1;
		}
	}
}
0