結果

問題 No.325 マンハッタン距離2
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-15 02:37:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 86,656 KB
実行使用メモリ 71,228 KB
最終ジャッジ日時 2023-09-04 01:26:41
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,216 KB
testcase_01 AC 71 ms
71,072 KB
testcase_02 AC 71 ms
71,080 KB
testcase_03 AC 72 ms
71,048 KB
testcase_04 AC 70 ms
71,164 KB
testcase_05 AC 71 ms
71,184 KB
testcase_06 WA -
testcase_07 AC 71 ms
71,084 KB
testcase_08 AC 70 ms
71,132 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
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 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

x1, y1, x2, y2, d = map(int, input().split())

if x1 <= 0 <= x2 and y1 <= 0 <= y2:
    d_ = d+min(abs(x1), abs(x2))+min(abs(y1), abs(y2))
else:
    d_ = d-min(abs(x1), abs(x2))-min(abs(y1), abs(y2))

if d_ < 0:
    print(0)

dx = 0
dy = 0
m = 0
for x, y in (x1, y1), (x1, y2), (x2, y1), (x2, y2):
    temp = abs(x)+abs(y)
    if temp <= m:
        dx = x
        dy = y
        m = temp

X = max(abs(x2-dx), abs(x1-dx))
Y = max(abs(y2-dy), abs(y1-dy))
if Y > X:
    X, Y = Y, X

#print(X, Y)
ans = 0
if 0 <= d_ <= Y:
    ans = (d_+1)+d_*(d_+1)//2
elif Y < d_ <= X:
    ans = (Y+1)+Y*(Y+1)//2
    ans += (Y+1)*(d_-(Y+1)+1)
elif X < d_ <= X+Y:
    ans = (Y+1)+Y*(Y+1)//2
    ans += (Y+1)*(X-(Y+1)+1)
    ans += (X+Y+1)*(d_-(X+1)+1)
    ans -= (d_)*(d_+1)//2-X*(X+1)//2
else:
    ans = (Y+1)+Y*(Y+1)//2
    ans += (Y+1)*(X-(Y+1)+1)
    ans += (X+Y+1)*(X+Y-(X+1)+1)
    ans -= (X+Y)*(X+Y+1)//2-X*(X+1)//2
print(ans)
0