結果

問題 No.1999 Lattice Teleportation
ユーザー tnodinotnodino
提出日時 2022-07-02 00:54:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,812 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 11,392 KB
実行使用メモリ 82,932 KB
最終ジャッジ日時 2023-08-17 12:42:59
合計ジャッジ時間 39,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
9,168 KB
testcase_01 AC 21 ms
9,188 KB
testcase_02 AC 21 ms
9,128 KB
testcase_03 AC 22 ms
9,380 KB
testcase_04 AC 26 ms
9,308 KB
testcase_05 AC 43 ms
10,060 KB
testcase_06 AC 42 ms
9,792 KB
testcase_07 AC 33 ms
9,592 KB
testcase_08 AC 26 ms
9,528 KB
testcase_09 AC 21 ms
9,172 KB
testcase_10 AC 22 ms
9,048 KB
testcase_11 WA -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 22 ms
9,368 KB
testcase_15 TLE -
testcase_16 WA -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 WA -
testcase_24 WA -
testcase_25 TLE -
testcase_26 WA -
testcase_27 WA -
testcase_28 TLE -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd, sqrt, acos, pi
from collections import deque
mod = 10**9+7

class Point:
    def __init__(self, px, py):
        self.px = px
        self.py = py

def operator_p(a1, a2):
    return Point(a1.px + a2.px, a1.py + a2.py)

def operator_m(a1, a2):
    return Point(a1.px - a2.px, a1.py - a2.py)

def operator(a1, a2):
    if a1.px < a2.px:
        return True
    if a1.px > a2.px:
        return False
    if a1.py < a2.py:
        return True
    return False

def getangle(G):
    # 点 G の偏角を求める
    if G.py >= 0.0:
        I = G.px / sqrt(pow(G.px, 2) + pow(G.py, 2))
        kaku = acos(I) * 180.0 / pi
        return kaku
    else:
        I = G.px / sqrt(pow(G.px, 2) + pow(G.py, 2))
        kaku = acos(I) * 180.0 / pi
        return 360.0 - kaku

# 点 p1 と p2 の外積を求める
def crs(p1, p2):
    return p1.px * p2.py - p1.py * p2.px

N = int(input())
Z = []
for i in range(N):
    A,B = map(int,input().split())
    if A == 0 and B == 0:
        continue
    if B < 0:
        A *= -1
        B *= -1
    Z.append(Point(A, B))
N = len(Z)

vec = []
for i in range(N):
    SA = operator_m(Point(0, 0), Z[i])
    angle = getangle(SA)
    vec.append([angle, Z[i].px, Z[i].py])
vec.sort()

P = [Point(0, 0)]
Q = [Point(0, 0)]
x,y = 0,0
for i in range(N):
    x += vec[i][1]
    y += vec[i][2]
    P.append(Point(x, y))
x,y = 0,0
for i in range(N):
    x += vec[N-i-1][1]
    y += vec[N-i-1][2]
    Q.append(Point(x, y))

G = []
for i in range(N+1):
    G.append(P[i])
for i in range(N-1,0,-1):
    G.append(Q[i])
if len(G) == 1:
    print(1)
    exit()

G1 = deque()
G2 = deque()
Totsuhou = []
G1.append(G[0])
G2.append(G[0])
G1.append(G[1])
G2.append(G[1])
for i in range(2,len(G)):
    while len(G1) >= 2 and crs(operator_m(G1[len(G1)-1], G1[len(G1)-2]), operator_m(G[i], G1[len(G1)-1])) <= 0:
        G1.pop()
    while len(G2) >= 2 and crs(operator_m(G2[len(G2)-1], G2[len(G2)-2]), operator_m(G[i], G2[len(G2)-1])) >= 0:
        G2.pop()
    G1.append(G[i])
    G2.append(G[i])
G1 = list(G1)
G2 = list(G2)
for i in range(len(G1)):
    Totsuhou.append(G1[i])
for i in range(len(G2)-2,0,-1):
    Totsuhou.append(G2[i])

EdgePoint = len(Totsuhou)
for i in range(len(Totsuhou)):
    ax = Totsuhou[(i+0) % len(Totsuhou)].px
    ay = Totsuhou[(i+0) % len(Totsuhou)].py
    bx = Totsuhou[(i+1) % len(Totsuhou)].px
    by = Totsuhou[(i+1) % len(Totsuhou)].py
    vx = abs(bx - ax)
    vy = abs(by - ay)
    r = gcd(vx, vy)
    EdgePoint += r - 1

Area = 0
for i in range(len(Totsuhou)):
    ax = Totsuhou[(i+0) % len(Totsuhou)].px
    ay = Totsuhou[(i+0) % len(Totsuhou)].py
    bx = Totsuhou[(i+1) % len(Totsuhou)].px
    by = Totsuhou[(i+1) % len(Totsuhou)].py
    Area += (bx - ax) * (by + ay)
Area = abs(Area)

Answer = Area + EdgePoint + 2
print(Answer // 2 % mod)
0