結果
問題 | No.1999 Lattice Teleportation |
ユーザー | とりゐ |
提出日時 | 2022-07-01 23:50:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 699 ms / 2,000 ms |
コード長 | 2,003 bytes |
コンパイル時間 | 1,368 ms |
コンパイル使用メモリ | 86,852 KB |
実行使用メモリ | 121,484 KB |
最終ジャッジ日時 | 2023-08-17 11:37:37 |
合計ジャッジ時間 | 13,337 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,012 KB |
testcase_01 | AC | 74 ms
71,600 KB |
testcase_02 | AC | 76 ms
71,456 KB |
testcase_03 | AC | 75 ms
71,012 KB |
testcase_04 | AC | 87 ms
75,764 KB |
testcase_05 | AC | 132 ms
77,748 KB |
testcase_06 | AC | 135 ms
77,876 KB |
testcase_07 | AC | 101 ms
76,044 KB |
testcase_08 | AC | 85 ms
76,016 KB |
testcase_09 | AC | 74 ms
71,408 KB |
testcase_10 | AC | 73 ms
71,324 KB |
testcase_11 | AC | 130 ms
77,500 KB |
testcase_12 | AC | 505 ms
108,620 KB |
testcase_13 | AC | 559 ms
111,832 KB |
testcase_14 | AC | 77 ms
71,440 KB |
testcase_15 | AC | 699 ms
121,484 KB |
testcase_16 | AC | 412 ms
95,548 KB |
testcase_17 | AC | 529 ms
114,324 KB |
testcase_18 | AC | 493 ms
109,048 KB |
testcase_19 | AC | 604 ms
113,012 KB |
testcase_20 | AC | 573 ms
112,832 KB |
testcase_21 | AC | 572 ms
118,340 KB |
testcase_22 | AC | 575 ms
110,468 KB |
testcase_23 | AC | 270 ms
82,532 KB |
testcase_24 | AC | 323 ms
89,296 KB |
testcase_25 | AC | 567 ms
103,828 KB |
testcase_26 | AC | 436 ms
98,656 KB |
testcase_27 | AC | 410 ms
98,308 KB |
testcase_28 | AC | 643 ms
108,360 KB |
testcase_29 | AC | 375 ms
93,844 KB |
testcase_30 | AC | 276 ms
84,760 KB |
testcase_31 | AC | 282 ms
83,800 KB |
testcase_32 | AC | 423 ms
100,324 KB |
ソースコード
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: continue 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))