結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,136 KB
testcase_01 AC 83 ms
15,152 KB
testcase_02 AC 78 ms
15,116 KB
testcase_03 AC 78 ms
15,200 KB
testcase_04 AC 77 ms
15,160 KB
testcase_05 AC 76 ms
15,196 KB
testcase_06 AC 79 ms
15,152 KB
testcase_07 AC 79 ms
15,204 KB
testcase_08 AC 77 ms
15,016 KB
testcase_09 AC 76 ms
15,020 KB
testcase_10 AC 78 ms
15,116 KB
testcase_11 AC 78 ms
15,152 KB
testcase_12 AC 77 ms
15,152 KB
testcase_13 AC 77 ms
15,160 KB
testcase_14 AC 76 ms
15,104 KB
testcase_15 AC 75 ms
15,112 KB
testcase_16 AC 74 ms
15,224 KB
testcase_17 AC 78 ms
15,016 KB
testcase_18 AC 75 ms
15,124 KB
testcase_19 AC 73 ms
14,976 KB
testcase_20 AC 74 ms
15,124 KB
testcase_21 AC 75 ms
15,012 KB
testcase_22 AC 76 ms
15,116 KB
testcase_23 AC 74 ms
15,120 KB
testcase_24 AC 73 ms
15,088 KB
testcase_25 AC 74 ms
15,256 KB
testcase_26 AC 75 ms
15,312 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
	exit
end
r=[d,x2].min+[d,-x1].min+[d,y2].min+[d,-y1].min+1
[-x1,x2].product([-y1,y2]){|x,y|
x-=1
y-=1
d0=[d-2,x+y].min
r+=(d0+1)*(d0+2)/2
r-=(d0-x)*(d0-x+1)/2 if x<d0
r-=(d0-y)*(d0-y+1)/2 if y<d0
}
p r
0