結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,236 KB
testcase_01 AC 74 ms
70,732 KB
testcase_02 AC 73 ms
70,724 KB
testcase_03 AC 73 ms
71,188 KB
testcase_04 AC 73 ms
70,724 KB
testcase_05 AC 73 ms
70,836 KB
testcase_06 WA -
testcase_07 AC 73 ms
70,808 KB
testcase_08 AC 73 ms
70,920 KB
testcase_09 AC 76 ms
71,140 KB
testcase_10 AC 73 ms
70,716 KB
testcase_11 AC 71 ms
71,056 KB
testcase_12 AC 72 ms
71,080 KB
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 AC 74 ms
70,948 KB
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dx = 0
dy = 0
m = float('inf')
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

if x1 <= 0 <= x2 and y1 <= 0 <= y2:
    d_ = d+m
else:
    d_ = d-m

if d_ < 0:
    print(0)

X = max(abs(x2-dx), abs(x1-dx))
Y = max(abs(y2-dy), abs(y1-dy))
if Y > X:
    X, Y = Y, X
#print(dx, dy)
#print(X, Y)
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