結果

問題 No.325 マンハッタン距離2
ユーザー tailstails
提出日時 2015-12-18 00:26:22
言語 Perl
(5.38.2)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 445 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 5,236 KB
実行使用メモリ 4,676 KB
最終ジャッジ日時 2023-10-14 13:29:21
合計ジャッジ時間 1,489 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,544 KB
testcase_01 AC 2 ms
4,568 KB
testcase_02 AC 2 ms
4,468 KB
testcase_03 AC 3 ms
4,604 KB
testcase_04 AC 2 ms
4,676 KB
testcase_05 AC 2 ms
4,480 KB
testcase_06 AC 2 ms
4,648 KB
testcase_07 AC 3 ms
4,500 KB
testcase_08 AC 2 ms
4,556 KB
testcase_09 AC 3 ms
4,552 KB
testcase_10 AC 2 ms
4,584 KB
testcase_11 AC 3 ms
4,604 KB
testcase_12 AC 2 ms
4,548 KB
testcase_13 AC 3 ms
4,468 KB
testcase_14 AC 3 ms
4,532 KB
testcase_15 AC 3 ms
4,464 KB
testcase_16 AC 2 ms
4,516 KB
testcase_17 AC 2 ms
4,520 KB
testcase_18 AC 3 ms
4,644 KB
testcase_19 AC 2 ms
4,448 KB
testcase_20 AC 3 ms
4,584 KB
testcase_21 AC 3 ms
4,544 KB
testcase_22 AC 3 ms
4,552 KB
testcase_23 AC 2 ms
4,572 KB
testcase_24 AC 2 ms
4,628 KB
testcase_25 AC 3 ms
4,568 KB
testcase_26 AC 3 ms
4,628 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

sub g{$_[0]>0&&$_[0]*(1+$_[0])/2}
sub f{
	my($x1,$y1,$x2,$y2,$d)=@_;
	($x1,$x2)=($x2,$x1)if$x1>$x2;
	($y1,$y2)=($y2,$y1)if$y1>$y2;
	return 0 if $x2<0||$y2<0||$d<0;
	$x2-=$x1,$d-=$x1 if$x1>0;
	$y2-=$y1,$d-=$y1 if$y1>0;
	return $d>$x2+$y2?($x2+1)*($y2+1):g($d+1)- g($d-$x2)- g($d-$y2);
}
$/=$";($x1,$y1,$x2,$y2,$d)=<>;
print f($x1,$y1,$x2,$y2,$d)+
f(-$x1-1,$y1,-$x2-1,$y2,$d-1)+
f($x1,-$y1-1,$x2,-$y2-1,$d-1)+
f(-$x1-1,-$y1-1,-$x2-1,-$y2-1,$d-2);
0