結果

問題 No.325 マンハッタン距離2
ユーザー mkawa2
提出日時 2020-02-27 12:17:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 30 ms / 1,000 ms
コード長 1,408 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-10-13 15:51:24
合計ジャッジ時間 1,549 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

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]
# dist
def tri(dist):
return (dist+2)*(dist+1)//2
#
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()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0