結果

問題 No.325 マンハッタン距離2
ユーザー cielciel
提出日時 2015-12-19 06:12:20
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 1,000 ms
コード長 380 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,392 KB
実行使用メモリ 15,316 KB
最終ジャッジ日時 2023-08-27 06:08:51
合計ジャッジ時間 3,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,248 KB
testcase_01 AC 84 ms
15,180 KB
testcase_02 AC 82 ms
15,140 KB
testcase_03 AC 82 ms
15,184 KB
testcase_04 AC 81 ms
15,136 KB
testcase_05 AC 83 ms
15,292 KB
testcase_06 AC 82 ms
15,316 KB
testcase_07 AC 82 ms
15,096 KB
testcase_08 AC 83 ms
15,216 KB
testcase_09 AC 82 ms
15,136 KB
testcase_10 AC 82 ms
15,268 KB
testcase_11 AC 82 ms
15,248 KB
testcase_12 AC 83 ms
15,120 KB
testcase_13 AC 82 ms
15,140 KB
testcase_14 AC 82 ms
15,012 KB
testcase_15 AC 82 ms
15,080 KB
testcase_16 AC 83 ms
15,128 KB
testcase_17 AC 82 ms
15,128 KB
testcase_18 AC 81 ms
15,104 KB
testcase_19 AC 82 ms
15,232 KB
testcase_20 AC 82 ms
15,212 KB
testcase_21 AC 82 ms
15,300 KB
testcase_22 AC 83 ms
15,092 KB
testcase_23 AC 82 ms
15,088 KB
testcase_24 AC 82 ms
15,148 KB
testcase_25 AC 81 ms
15,100 KB
testcase_26 AC 81 ms
15,252 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
x1,y1,x2,y2,d=gets.split.map(&:to_i)
x1,x2=-x2,-x1 if x2<0
y1,y2=-y2,-y1 if y2<0
x1,x2,d=0,x2-x1,d-x1 if x1>0
y1,y2,d=0,y2-y1,d-y1 if y1>0
if d<0
	p 0
else
	r=[d,x2].min+[d,-x1].min+[d,y2].min+[d,-y1].min+1
	[-x1,x2].product([-y1,y2]){|x,y|
		d0=[d-2,x+y-2].min
		r+=(d0+1)*(d0+2)/2
		r-=(d0-x+1)*(d0-x+2)/2 if x-1<d0
		r-=(d0-y+1)*(d0-y+2)/2 if y-1<d0
	}
	p r
end
0