結果

問題 No.1999 Lattice Teleportation
ユーザー とりゐとりゐ
提出日時 2022-07-02 00:51:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,147 ms / 2,000 ms
コード長 2,309 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 202,560 KB
最終ジャッジ日時 2023-08-17 12:39:38
合計ジャッジ時間 20,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,720 KB
testcase_01 AC 72 ms
71,612 KB
testcase_02 AC 70 ms
71,436 KB
testcase_03 AC 72 ms
71,488 KB
testcase_04 AC 123 ms
76,172 KB
testcase_05 AC 156 ms
79,448 KB
testcase_06 AC 147 ms
79,684 KB
testcase_07 AC 109 ms
77,500 KB
testcase_08 AC 81 ms
76,480 KB
testcase_09 AC 70 ms
71,728 KB
testcase_10 AC 71 ms
71,628 KB
testcase_11 AC 154 ms
79,136 KB
testcase_12 AC 975 ms
202,560 KB
testcase_13 AC 1,083 ms
202,404 KB
testcase_14 AC 69 ms
71,568 KB
testcase_15 AC 1,098 ms
195,220 KB
testcase_16 AC 747 ms
142,692 KB
testcase_17 AC 773 ms
185,212 KB
testcase_18 AC 710 ms
174,304 KB
testcase_19 AC 994 ms
183,404 KB
testcase_20 AC 1,136 ms
196,740 KB
testcase_21 AC 1,147 ms
193,040 KB
testcase_22 AC 1,140 ms
196,452 KB
testcase_23 AC 338 ms
88,172 KB
testcase_24 AC 582 ms
118,964 KB
testcase_25 AC 712 ms
168,908 KB
testcase_26 AC 625 ms
154,176 KB
testcase_27 AC 795 ms
146,524 KB
testcase_28 AC 825 ms
183,408 KB
testcase_29 AC 706 ms
136,504 KB
testcase_30 AC 465 ms
104,348 KB
testcase_31 AC 356 ms
95,872 KB
testcase_32 AC 603 ms
144,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def compare(a,b):
  # 比較関数 (a<=b)
  
  # 偏角ソート
  ax, ay = a
  bx, by = b
  if ay < 0:
    return by >= 0 or ax * by - ay * bx > 0
  if ay == 0:
    return ax >= 0 and (by > 0 or (by == 0 and bx < 0))
  return by >= 0 and (ax * by - ay * bx) > 0


def merge(l, r):
    new = []
    ln = 0
    rn = 0
    while ln < len(l) and rn < len(r):
        if compare(l[ln],r[rn]):
            new.append(l[ln])
            ln += 1
        else:
            new.append(r[rn])
            rn += 1
    for i in range(ln, len(l)):
        new.append(l[i])
    for i in range(rn, len(r)):
        new.append(r[i])
    return new
 
def MergeSort(l):
    if len(l) == 0:
        return []
    if len(l) == 1:
        return l
    else:
        a = l[:len(l)//2]
        b = l[len(l)//2:]
        return merge(MergeSort(a), MergeSort(b))

n=int(input())
xy=[]
for i in range(n):
  x,y=map(int,input().split())
  if x==y==0:
    pass
  xy.append((x,y))
xy=MergeSort(xy)
m=len(xy)
xy2=[]

from math import atan2,degrees

for x,y in xy:
  xy2.append((x,y,degrees(atan2(y,x))))


for x,y in xy:
  xy2.append((x,y,degrees(atan2(y,x))+360))


for x,y in xy:
  xy2.append((x,y,degrees(atan2(y,x))+720))
xy=xy2

XY=[]
tmpx,tmpy=0,0
R=-1
for L in range(m):
  Lx,Ly,Lrad=xy[L]
  while True:
    XY.append((tmpx,tmpy))
    Rx,Ry,Rrad=xy[R+1]
    if Ry*Lx-Ly*Rx>=0 and Rrad-Lrad<181:
      tmpx+=Rx
      tmpy+=Ry
      R+=1
    else:
      break
  tmpx-=Lx
  tmpy-=Ly

def cross3(a, b, c):
    return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])
 
# ps = [(x, y), ...]: ソートされた座標list
def convex_hull(ps):
    qs = []
    N = len(ps)
    for p in ps:
        # 一直線上で高々2点にする場合は ">=" にする
        while len(qs) > 1 and cross3(qs[-1], qs[-2], p) >= 0:
            qs.pop()
        qs.append(p)
    t = len(qs)
    for i in range(N-2, -1, -1):
        p = ps[i]
        while len(qs) > t and cross3(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs

from math import gcd
XY=set(XY)
XY=list(XY)

XY.sort()
ch=convex_hull(XY)
m=len(ch)-1
area=0
point_cnt=0
use_cnt=0
for i in range(m):
  x1,y1=ch[i]
  x2,y2=ch[i+1]
  area+=x1*y2-x2*y1
  point_cnt+=gcd(x1-x2,y1-y2)
point_cnt2=(area-point_cnt)//2+1
ans=point_cnt+point_cnt2
print(ans%(10**9+7))
0