結果

問題 No.325 マンハッタン距離2
ユーザー mkawa2mkawa2
提出日時 2020-02-27 12:17:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 1,000 ms
コード長 1,408 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-21 16:53:17
合計ジャッジ時間 1,902 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# 1辺の長さがdistの三角形に含まれる格子点の数(辺上を含む)
def tri(dist):
    return (dist+2)*(dist+1)//2

# 1つの象限内の格子点を数える
def cal(l,b,r,t,d):
    cor=[l+b,l+t,b+r,r+t]
    cor.sort()
    if d<cor[0]:return 0
    elif d==cor[0]:return 1
    elif d<cor[1]:
        dist=d-cor[0]
        return tri(dist)
    elif d<cor[2]:
        dist1=d-cor[0]
        dist2=d-cor[1]-1
        return tri(dist1)-tri(dist2)
    elif d<cor[3]:
        dist=cor[3]-d-1
        return (r-l+1)*(t-b+1)-tri(dist)
    return (r-l+1)*(t-b+1)

def main():
    x1,y1,x2,y2,d=MI()
    ans=0
    if x2>0 and y2>0:ans+=cal(max(0,x1),max(0,y1),x2,y2,d)
    if x1<0 and y2>0:ans+=cal(max(0,-x2),max(0,y1),-x1,y2,d)
    if x1<0 and y1<0:ans+=cal(max(0,-x2),max(0,-y2),-x1,-y1,d)
    if x2>0 and y1<0:ans+=cal(max(0,x1),max(0,-y2),x2,-y1,d)
    if y1<0 and y2>0:ans-=min(d,x2)-max(-d,x1)+1
    if x1<0 and x2>0:ans-=min(d,y2)-max(-d,y1)+1
    if y1<0 and y2>0 and x1<0 and x2>0:ans-=1
    print(ans)

main()
0