結果

問題 No.325 マンハッタン距離2
ユーザー cielciel
提出日時 2015-12-19 06:09:42
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 347 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,564 KB
実行使用メモリ 15,400 KB
最終ジャッジ日時 2023-10-14 14:11:39
合計ジャッジ時間 3,738 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,280 KB
testcase_01 AC 83 ms
15,204 KB
testcase_02 AC 83 ms
15,240 KB
testcase_03 AC 82 ms
15,052 KB
testcase_04 AC 83 ms
15,232 KB
testcase_05 AC 86 ms
15,072 KB
testcase_06 WA -
testcase_07 AC 82 ms
15,348 KB
testcase_08 AC 81 ms
15,240 KB
testcase_09 AC 82 ms
15,316 KB
testcase_10 AC 81 ms
15,340 KB
testcase_11 AC 82 ms
15,268 KB
testcase_12 AC 82 ms
15,168 KB
testcase_13 AC 82 ms
15,056 KB
testcase_14 AC 82 ms
15,184 KB
testcase_15 AC 83 ms
15,280 KB
testcase_16 AC 83 ms
15,140 KB
testcase_17 AC 83 ms
15,136 KB
testcase_18 AC 84 ms
15,168 KB
testcase_19 AC 84 ms
15,292 KB
testcase_20 WA -
testcase_21 AC 84 ms
15,268 KB
testcase_22 AC 84 ms
15,240 KB
testcase_23 AC 83 ms
15,164 KB
testcase_24 AC 83 ms
15,380 KB
testcase_25 AC 82 ms
15,056 KB
testcase_26 AC 82 ms
15,292 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
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