結果

問題 No.2173 Nightcord
ユーザー chineristACchineristAC
提出日時 2022-12-25 02:51:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,801 ms / 2,525 ms
コード長 3,506 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 83,872 KB
最終ジャッジ日時 2024-04-28 19:27:39
合計ジャッジ時間 36,017 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
56,704 KB
testcase_01 AC 50 ms
56,704 KB
testcase_02 AC 50 ms
56,704 KB
testcase_03 AC 1,345 ms
81,664 KB
testcase_04 AC 51 ms
57,088 KB
testcase_05 AC 93 ms
77,568 KB
testcase_06 AC 59 ms
67,328 KB
testcase_07 AC 81 ms
77,440 KB
testcase_08 AC 98 ms
77,568 KB
testcase_09 AC 1,007 ms
80,592 KB
testcase_10 AC 588 ms
78,764 KB
testcase_11 AC 121 ms
77,056 KB
testcase_12 AC 926 ms
79,872 KB
testcase_13 AC 152 ms
77,312 KB
testcase_14 AC 1,314 ms
81,920 KB
testcase_15 AC 1,307 ms
81,664 KB
testcase_16 AC 62 ms
68,992 KB
testcase_17 AC 246 ms
77,440 KB
testcase_18 AC 671 ms
78,848 KB
testcase_19 AC 71 ms
71,296 KB
testcase_20 AC 650 ms
78,848 KB
testcase_21 AC 870 ms
79,616 KB
testcase_22 AC 963 ms
80,896 KB
testcase_23 AC 913 ms
80,512 KB
testcase_24 AC 1,688 ms
82,688 KB
testcase_25 AC 1,168 ms
81,152 KB
testcase_26 AC 1,431 ms
81,836 KB
testcase_27 AC 82 ms
74,624 KB
testcase_28 AC 1,305 ms
82,432 KB
testcase_29 AC 277 ms
77,056 KB
testcase_30 AC 1,801 ms
83,444 KB
testcase_31 AC 411 ms
77,952 KB
testcase_32 AC 677 ms
79,616 KB
testcase_33 AC 1,185 ms
81,536 KB
testcase_34 AC 1,276 ms
83,872 KB
testcase_35 AC 692 ms
79,744 KB
testcase_36 AC 793 ms
79,872 KB
testcase_37 AC 1,129 ms
82,432 KB
testcase_38 AC 253 ms
77,952 KB
testcase_39 AC 639 ms
79,616 KB
testcase_40 AC 1,242 ms
83,072 KB
testcase_41 AC 821 ms
79,616 KB
testcase_42 AC 833 ms
80,184 KB
testcase_43 AC 172 ms
77,160 KB
testcase_44 AC 51 ms
57,344 KB
testcase_45 AC 374 ms
77,824 KB
testcase_46 AC 510 ms
78,336 KB
testcase_47 AC 493 ms
78,164 KB
testcase_48 AC 277 ms
77,568 KB
testcase_49 AC 80 ms
73,472 KB
testcase_50 AC 150 ms
77,200 KB
testcase_51 AC 533 ms
78,464 KB
testcase_52 AC 73 ms
70,912 KB
testcase_53 AC 564 ms
78,752 KB
testcase_54 AC 773 ms
79,188 KB
testcase_55 AC 226 ms
76,928 KB
testcase_56 AC 382 ms
77,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
from itertools import cycle, permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

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

# O(N)
def inside_convex_polygon0(p0, qs):
    L = len(qs)
    D = [cross3(qs[i-1], p0, qs[i]) for i in range(L)]
    return all(e >= 0 for e in D) or all(e <= 0 for e in D)

# O(log N)
def inside_convex_polygon(p0, qs):
    L = len(qs)
    left = 1; right = L
    q0 = qs[0]
    while left+1 < right:
        mid = (left + right) >> 1
        if cross3(q0, p0, qs[mid]) <= 0:
            left = mid
        else:
            right = mid
    if left == L-1:
        left -= 1
    qi = qs[left]; qj = qs[left+1]
    v0 = cross3(q0, qi, qj)
    v1 = cross3(q0, p0, qj)
    v2 = cross3(q0, qi, p0)
    if v0 < 0:
        v1 = -v1; v2 = -v2
    return 0 <= v1 and 0 <= v2 and v1 + v2 <= v0

# 線分同士の交点判定
def dot3(O, A, B):
    ox, oy = O; ax, ay = A; bx, by = B
    return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy)
def cross3(O, A, B):
    ox, oy = O; ax, ay = A; bx, by = B
    return (ax - ox) * (by - oy) - (bx - ox) * (ay - oy)
def dist2(A, B):
    ax, ay = A; bx, by = B
    return (ax - bx) ** 2 + (ay - by) ** 2
def is_intersection(P0, P1, Q0, Q1):
    C0 = cross3(P0, P1, Q0)
    C1 = cross3(P0, P1, Q1)
    D0 = cross3(Q0, Q1, P0)
    D1 = cross3(Q0, Q1, P1)
    if C0 == C1 == 0:
        E0 = dot3(P0, P1, Q0)
        E1 = dot3(P0, P1, Q1)
        if not E0 < E1:
            E0, E1 = E1, E0
        return E0 <= dist2(P0, P1) and 0 <= E1
    return C0 * C1 <= 0 and D0 * D1 <= 0





def solve_3(N,K,star):

    for p in range(2):
        for x,y in star[p]:
            S = set()
            for xx,yy in star[p^1]:
                xx,yy = xx-x,yy-y
                g = gcd(xx,yy)
                xx,yy = xx//g,yy//g
                if (-xx,-yy) in S:
                    return "Yes"
                S.add((xx,yy))

    return "No"

def solve_4(N,K,star):
    if solve_3(N,K,star) == "Yes":
        return "Yes"

    star[0].sort()
    star[1].sort()

    ch = [convex_hull(star[p]) for p in range(2)]
    for p in range(2):
        if len(star[p^1]) > 2:
            for i in range(len(ch[p])-1):
                x,y = ch[p][i]
                if inside_convex_polygon((x,y),ch[p^1]):
                    return "Yes"
        if len(star[p]) == 2:
            a,b = star[p][0],star[p][1]
            for i in range(len(ch[p^1])-1):
                c,d = ch[p^1][i],ch[p^1][i+1]
                if is_intersection(a,b,c,d):
                    return "Yes"
    
    return "No"



N,K = mi()
star = [[] for p in range(2)]
for _ in range(N):
    x,y,c = mi()
    star[c-1].append((x,y))

if len(star[0])==1 or len(star[1])==1:
    exit(print("Yes"))

if K == 3:
    print(solve_3(N,K,star))
else:
    print(solve_4(N,K,star))
0