結果

問題 No.1999 Lattice Teleportation
ユーザー とりゐとりゐ
提出日時 2022-07-01 23:44:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,999 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 118,476 KB
最終ジャッジ日時 2023-08-17 11:31:12
合計ジャッジ時間 12,723 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,516 KB
testcase_01 AC 75 ms
71,288 KB
testcase_02 AC 75 ms
71,192 KB
testcase_03 AC 75 ms
71,320 KB
testcase_04 AC 88 ms
75,876 KB
testcase_05 AC 131 ms
77,728 KB
testcase_06 AC 132 ms
77,828 KB
testcase_07 AC 100 ms
75,952 KB
testcase_08 AC 86 ms
75,884 KB
testcase_09 AC 76 ms
71,304 KB
testcase_10 AC 74 ms
71,244 KB
testcase_11 AC 132 ms
77,684 KB
testcase_12 AC 510 ms
108,480 KB
testcase_13 AC 561 ms
111,656 KB
testcase_14 WA -
testcase_15 AC 584 ms
111,024 KB
testcase_16 AC 414 ms
95,256 KB
testcase_17 AC 530 ms
114,488 KB
testcase_18 AC 498 ms
108,976 KB
testcase_19 AC 616 ms
112,976 KB
testcase_20 AC 581 ms
112,848 KB
testcase_21 AC 574 ms
118,476 KB
testcase_22 AC 577 ms
110,660 KB
testcase_23 AC 277 ms
82,216 KB
testcase_24 AC 329 ms
89,308 KB
testcase_25 AC 567 ms
104,172 KB
testcase_26 AC 438 ms
98,528 KB
testcase_27 AC 413 ms
98,184 KB
testcase_28 AC 651 ms
108,464 KB
testcase_29 AC 382 ms
93,596 KB
testcase_30 AC 282 ms
84,520 KB
testcase_31 AC 279 ms
83,588 KB
testcase_32 AC 424 ms
100,228 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
  if y<0:
    x,y=-x,-y
  xy.append((x,y))
xy=MergeSort(xy)
m=len(xy)

XY=[(0,0)]
cumx,cumy=0,0
for x,y in xy:
  cumx+=x
  cumy+=y
  XY.append((cumx,cumy))

cumx,cumy=0,0
for x,y in xy[::-1]:
  cumx+=x
  cumy+=y
  XY.append((cumx,cumy))

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.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