結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 28 ms
10,880 KB
testcase_05 AC 25 ms
10,880 KB
testcase_06 AC 26 ms
10,880 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 27 ms
10,880 KB
testcase_09 AC 26 ms
10,752 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 27 ms
10,752 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 27 ms
10,880 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 27 ms
10,880 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 26 ms
10,880 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