結果

問題 No.1497 Triangle
ユーザー 👑 tatyamtatyam
提出日時 2021-05-02 02:25:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 2,794 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 113,568 KB
最終ジャッジ日時 2023-09-27 16:20:51
合計ジャッジ時間 15,604 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
71,764 KB
testcase_01 AC 82 ms
71,972 KB
testcase_02 AC 84 ms
71,864 KB
testcase_03 AC 202 ms
79,948 KB
testcase_04 AC 230 ms
80,172 KB
testcase_05 AC 209 ms
79,588 KB
testcase_06 AC 82 ms
71,384 KB
testcase_07 AC 81 ms
71,552 KB
testcase_08 AC 97 ms
77,844 KB
testcase_09 AC 110 ms
78,188 KB
testcase_10 AC 87 ms
71,656 KB
testcase_11 AC 85 ms
71,360 KB
testcase_12 AC 81 ms
72,080 KB
testcase_13 AC 83 ms
71,932 KB
testcase_14 AC 83 ms
71,956 KB
testcase_15 AC 80 ms
71,848 KB
testcase_16 AC 83 ms
71,888 KB
testcase_17 AC 83 ms
71,928 KB
testcase_18 AC 85 ms
71,964 KB
testcase_19 AC 83 ms
71,912 KB
testcase_20 AC 90 ms
77,084 KB
testcase_21 AC 88 ms
77,224 KB
testcase_22 AC 516 ms
113,008 KB
testcase_23 AC 133 ms
78,584 KB
testcase_24 AC 355 ms
88,368 KB
testcase_25 AC 204 ms
79,760 KB
testcase_26 AC 112 ms
78,312 KB
testcase_27 AC 508 ms
112,800 KB
testcase_28 AC 347 ms
89,020 KB
testcase_29 AC 265 ms
82,192 KB
testcase_30 AC 162 ms
110,900 KB
testcase_31 AC 164 ms
110,704 KB
testcase_32 AC 368 ms
112,132 KB
testcase_33 AC 383 ms
112,512 KB
testcase_34 AC 434 ms
112,992 KB
testcase_35 AC 431 ms
112,844 KB
testcase_36 AC 441 ms
112,832 KB
testcase_37 AC 451 ms
112,984 KB
testcase_38 AC 412 ms
113,568 KB
testcase_39 AC 411 ms
112,876 KB
testcase_40 AC 442 ms
112,836 KB
testcase_41 AC 450 ms
112,832 KB
testcase_42 AC 546 ms
113,360 KB
testcase_43 AC 467 ms
113,488 KB
testcase_44 AC 180 ms
79,640 KB
testcase_45 AC 406 ms
112,816 KB
testcase_46 AC 443 ms
113,012 KB
testcase_47 AC 438 ms
112,592 KB
testcase_48 AC 473 ms
112,872 KB
testcase_49 AC 506 ms
112,940 KB
testcase_50 AC 505 ms
112,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import *
EPS = 1e-10
INF = float("inf")
N = int(input())
P = [tuple(map(int, input().split())) for i in range(N)]
P.sort(reverse=True)

def cross(i, j, k):
    x0, y0 = P[i]
    x1, y1 = P[j]
    x2, y2 = P[k]
    x1 -= x0
    x2 -= x0
    y1 -= y0
    y2 -= y0
    return x1 * y2 - x2 * y1

def dot(i, j, k):
    x0, y0 = P[i]
    x1, y1 = P[j]
    x2, y2 = P[k]
    x1 -= x0
    x2 -= x0
    y1 -= y0
    y2 -= y0
    return x1 * x2 + y1 * y2

def normal(i, j):
    return atan2(P[j][1] - P[i][1], P[j][0] - P[i][0]) + pi / 2

class Line:
    def __init__(self):
        self.mn = INF
        self.mx = -INF
        self.rev = False
    def update(self, sl):
        if sl < 0:
            sl += 2 * pi
        if self.rev and sl < pi:
            sl += 2 * pi
        if self.mn > sl:
            self.mn = sl
        if self.mx < sl:
            self.mx = sl
        assert pi > self.mx - self.mn >= 0

lines = defaultdict(Line)

for i in range(N - 1):
    if P[i][0] != P[i + 1][0]:
        lines[(1 << i + 1) - 1].rev = True

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        bit1 = 0
        bit2 = 0
        for k in range(N):
            c = cross(i, j, k)
            if c > 0:
                bit1 ^= 1 << k
                bit2 ^= 1 << k
            elif c == 0:
                if dot(i, j, k) > 0:
                    bit1 ^= 1 << k
                else:
                    bit2 ^= 1 << k
        theta = normal(i, j)
        lines[bit1].update(theta - EPS)
        lines[bit2].update(theta + EPS)

lines = list(lines.items())

ans = [False] * (1 << N)
ans[0] = ans[-1] = True

for bit1, _ in lines:
    for bit2, _ in lines:
        ans[bit1 & bit2] = True

def solve(l1, r1, l2, r2, l3, r3):
    if l1 > l2:
        l1, l2 = l2, l1
        r1, r2 = r2, r1
    if l2 > l3:
        l2, l3 = l3, l2
        r2, r3 = r3, r2
    if l1 > l2:
        l1, l2 = l2, l1
        r1, r2 = r2, r1
    if max(r1, r2, r3) - min(l1, l2, l3) < pi:
        return False
    l1 += 2 * pi
    r1 += 2 * pi
    if max(r1, r2, r3) - min(l1, l2, l3) < pi:
        return False
    l2 += 2 * pi
    r2 += 2 * pi
    if max(r1, r2, r3) - min(l1, l2, l3) < pi:
        return False
    return True

L = len(lines)
for i in range(L):
    bit1, l1 = lines[i]
    for j in range(i):
        bit2, l2 = lines[j]
        if not (bit1 & bit2 and bit1 & ~bit2 and ~bit1 & bit2):
            continue
        for k in range(j):
            bit3, l3 = lines[k]
            if not (bit1 & bit2 & bit3 and bit1 & bit2 & ~bit3 and bit1 & ~bit2 & bit3 and ~bit1 & bit2 & bit3):
                continue
            if solve(l1.mn, l1.mx, l2.mn, l2.mx, l3.mn, l3.mx):
                ans[bit1 & bit2 & bit3] = True

print(sum(ans))
0