結果

問題 No.325 マンハッタン距離2
ユーザー kurenaifkurenaif
提出日時 2016-06-29 22:16:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 728 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 04:36:25
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 27 ms
10,880 KB
testcase_03 WA -
testcase_04 AC 29 ms
10,880 KB
testcase_05 AC 28 ms
10,752 KB
testcase_06 AC 28 ms
11,008 KB
testcase_07 WA -
testcase_08 AC 28 ms
10,880 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 28 ms
10,880 KB
testcase_13 AC 28 ms
10,880 KB
testcase_14 AC 27 ms
10,752 KB
testcase_15 AC 27 ms
10,880 KB
testcase_16 AC 31 ms
10,880 KB
testcase_17 WA -
testcase_18 AC 27 ms
11,008 KB
testcase_19 AC 27 ms
10,880 KB
testcase_20 AC 28 ms
10,880 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python3

def S(x):
    if x < 0:
        return 0
    return (x)*(x+1)/2

def solve(x, y, dd):
    d = min(x+y,dd)
    return S(d+1) - (S(d-x) + S(d-y))

x1, y1, x2, y2, d = list(map(int, input().split()))
if x1 > 0:
    d -= x1;
    x2 -= x1;
    x1 = 0
if y1 > 0:
    d -= y1
    y2 -= y1
    y1 = 0
if x2 < 0:
    d += x2
    x1 += x2;
    x2 = 0
if y2 < 0:
    d += y2
    y1 += y2;
    y2 = 0

if d <= 0:
    print(0)
    exit()
    
x1 = abs(x1)
x2 = abs(x2)
y1 = abs(y1)
y2 = abs(y2)

res = 0
res += (solve(x1,y1,d))
res += (solve(x1,y2,d))
res += (solve(x2,y1,d))
res += (solve(x2,y2,d))

x1 = min(d,abs(x1))
y1 = min(d,abs(y1))
x2 = min(d,abs(x2))
y2 = min(d,abs(y2))

res -= (x1+x2+y1+y2+3)
print(int(res))
0