結果

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

テストケース

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

ソースコード

diff #

#!/usr/bin/python3

def S(x):
    if x < 0:
        return 0

    a = x
    b = (x+1)
    if (a & 1) == 0:
        a >>= 1
    else:
        b >>= 1
    return (a)*(b)

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()

if d == 0:
    print(1)
    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