結果

問題 No.325 マンハッタン距離2
ユーザー LeonardoneLeonardone
提出日時 2015-12-18 03:36:10
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,546 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 11,316 KB
実行使用メモリ 15,368 KB
最終ジャッジ日時 2023-10-14 13:45:05
合計ジャッジ時間 3,133 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,228 KB
testcase_01 AC 76 ms
15,268 KB
testcase_02 AC 75 ms
15,232 KB
testcase_03 AC 77 ms
15,252 KB
testcase_04 AC 78 ms
15,196 KB
testcase_05 AC 75 ms
15,144 KB
testcase_06 AC 76 ms
15,148 KB
testcase_07 AC 75 ms
15,064 KB
testcase_08 AC 76 ms
15,196 KB
testcase_09 WA -
testcase_10 AC 74 ms
15,196 KB
testcase_11 AC 75 ms
15,240 KB
testcase_12 AC 75 ms
15,060 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 75 ms
15,184 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 74 ms
15,060 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 74 ms
15,368 KB
testcase_24 AC 75 ms
15,184 KB
testcase_25 AC 76 ms
15,160 KB
testcase_26 AC 76 ms
15,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

def gs() gets.chomp end
def gi() gets.to_i end
def gss() gets.chomp.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end

x1, y1, x2, y2, d = gis




def f(x1,x2)
    case
    when x2 < 0
        [false, [[x2.abs,x1.abs].minmax]]
    when x2 == 0
        [true, [[1,x1.abs].minmax]]
    when x1 > 0
        [false,[[x1,x2].minmax]]
    when x1 == 0
        [true,[[1,x2].minmax]]
    else
        [true,[[1,x1.abs],[1,x2]]]
    end
end

zx, xs = f(x1,x2)
zy, ys = f(y1,y2)

c = (zx && zy) ? 1 : 0

for2p(xs, ys) {|(x0,x1),(y0,y1)|
    lx = x1 - x0 + 1
    ly = y1 - y0 + 1
    m0 = x0 + y0
    m1 = x1 + y1
    l0 = d - m0 + 1
    case
    when d < m0
        c += 0
    when m1 <= d
        c += lx * ly
    when l0 <= lx && l0 <= ly
        c += nsum(l0)
    when l0 <= lx # && ly < l0
        c += nsum(l0) - nsum(lx - ly)
    when l0 <= ly # && lx < l0
        c += nsum(l0) - nsum(ly - lx)
    else
        c += nsum(l0) - nsum(l0 - lx) - nsum(l0 - ly)
    end
}

[[zx,ys], [zy,xs]].each do |z, zs|
    next if !z
    zs.each do |e0,e1|
        case
        when e1 < d
            c += e1 - e0 + 1
        when e0 <= d && d <= e1
            c += d - e0 + 1
        end
    end
end

puts c


0