結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
12,288 KB
testcase_01 WA -
testcase_02 AC 74 ms
12,288 KB
testcase_03 AC 78 ms
12,288 KB
testcase_04 AC 77 ms
12,160 KB
testcase_05 AC 73 ms
12,160 KB
testcase_06 AC 74 ms
12,288 KB
testcase_07 AC 78 ms
12,160 KB
testcase_08 AC 74 ms
12,160 KB
testcase_09 AC 76 ms
12,288 KB
testcase_10 AC 74 ms
12,288 KB
testcase_11 AC 76 ms
12,160 KB
testcase_12 AC 73 ms
12,032 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 73 ms
12,160 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 74 ms
12,288 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,1,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-2) if d>y2+x2
    #p ['',calc(d),calc(d-y2-1),calc(d-x2-1),calc(d-y2-x2-2),z]
    z
end

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