結果

問題 No.325 マンハッタン距離2
ユーザー kimiyukikimiyuki
提出日時 2016-06-28 20:38:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 03:46:08
合計ジャッジ時間 1,821 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,752 KB
testcase_01 AC 39 ms
10,752 KB
testcase_02 AC 37 ms
10,752 KB
testcase_03 WA -
testcase_04 AC 25 ms
10,752 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 32 ms
10,752 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 28 ms
10,752 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 31 ms
10,880 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 33 ms
10,752 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 32 ms
10,752 KB
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
def f(x, y, d): # [0, x) * [0, y)
    assert 0 <= x
    assert 0 <= y
    d = min(d, x + y - 2)
    ans = (d+1)*(d+2)//2
    if x < d:
        dx = d-x+1
        ans -= dx*(dx+1)//2
    if y < d:
        dy = d-y+1
        ans -= dy*(dy+1)//2
    return ans
x1, y1, x2, y2, d = map(int,input().split())
assert x1 < x2
assert y1 < y2
if x2 <= 0:
    x1, x2 = - x2, - x1
if y2 <= 0:
    y1, y2 = - y2, - y1
if x1 <= 0:
    x1, y1 = y1, x1
    x2, y2 = y2, x2
ans = 0
if x1 <= 0:
    assert x1 <= 0 <= x2
    assert y1 <= 0 <= y2
    ans += f(abs(x1),   abs(y1),   d)
    ans += f(abs(x1),   abs(y2)+1, d)
    ans += f(abs(x2)+1, abs(y1),   d)
    ans += f(abs(x2)+1, abs(y2)+1, d)
elif y1 <= 0:
    assert 0 <= x1 < x2
    assert y1 <= 0 <= y2
    ans -= f(x1,   abs(y1),   d)
    ans += f(x2+1, abs(y1),   d)
    ans -= f(x1,   abs(y2)+1, d)
    ans += f(x2+1, abs(y2)+1, d)
    ans -= x2-x1+1
else:
    assert 0 <= x1 < x2
    assert 0 <= y1 < y2
    ans += f(x1,   y1,   d)
    ans -= f(x1,   y2+1, d)
    ans -= f(x2+1, y1,   d)
    ans += f(x2+1, y2+1, d)
print(ans)
0