結果

問題 No.325 マンハッタン距離2
ユーザー maimai
提出日時 2017-08-28 23:08:04
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 586 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-24 01:59:02
合計ジャッジ時間 3,391 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
12,160 KB
testcase_01 AC 86 ms
12,032 KB
testcase_02 AC 83 ms
12,160 KB
testcase_03 AC 84 ms
12,160 KB
testcase_04 AC 82 ms
12,032 KB
testcase_05 AC 85 ms
12,288 KB
testcase_06 AC 82 ms
12,288 KB
testcase_07 AC 86 ms
12,288 KB
testcase_08 AC 87 ms
12,160 KB
testcase_09 AC 85 ms
12,160 KB
testcase_10 AC 85 ms
12,160 KB
testcase_11 AC 89 ms
12,032 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 80 ms
12,160 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 82 ms
12,032 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def solve(x1,y1,x2,y2,d)
    #p [x1,y1,x2,y2,d]
    return solve(-x2,y1,-x1,y2,d) if x1 < 0 && x2 < 0
    return solve(x1,-y2,x2,-y1,d) if y1 < 0 && y2 < 0
    return solve(0,y1,x2,y2,d)+solve(1,y1,-x1,y2,d-1) if x1 < 0
    return solve(x1,0,x2,y2,d)+solve(x1,0,x2,-y1,d-1) if y1 < 0
    
    def calc(d); (d+1)*(d+2)/2; end
    
    return 0 if x1+y1 > d
    
    d -= x1+y1
    x2-=x1
    y2-=y1
    
    z = calc(d)
    z -= calc(d-y2-1) if d>y2 
    z -= calc(d-x2-1) if d>x2
    z += calc(d-y2-x2-1) if d>y2+x2
    z
end

while cin = gets
    p solve(*(cin.split.map(&:to_i)))
end
0