結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,284 KB
testcase_01 AC 76 ms
15,084 KB
testcase_02 AC 78 ms
15,040 KB
testcase_03 AC 73 ms
15,132 KB
testcase_04 AC 72 ms
15,088 KB
testcase_05 AC 73 ms
15,292 KB
testcase_06 AC 76 ms
15,336 KB
testcase_07 AC 76 ms
15,344 KB
testcase_08 AC 73 ms
15,240 KB
testcase_09 AC 74 ms
15,272 KB
testcase_10 AC 74 ms
15,056 KB
testcase_11 AC 73 ms
15,124 KB
testcase_12 AC 75 ms
15,152 KB
testcase_13 AC 75 ms
15,280 KB
testcase_14 AC 73 ms
15,120 KB
testcase_15 AC 71 ms
15,136 KB
testcase_16 AC 71 ms
15,332 KB
testcase_17 AC 74 ms
15,080 KB
testcase_18 AC 72 ms
15,048 KB
testcase_19 AC 75 ms
15,256 KB
testcase_20 AC 76 ms
15,044 KB
testcase_21 AC 73 ms
15,088 KB
testcase_22 AC 73 ms
15,044 KB
testcase_23 AC 74 ms
15,280 KB
testcase_24 AC 74 ms
15,120 KB
testcase_25 AC 71 ms
15,144 KB
testcase_26 AC 73 ms
15,236 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
(p 0;exit)if d<0
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
0