結果

問題 No.2173 Nightcord
ユーザー chineristACchineristAC
提出日時 2022-12-25 02:29:50
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 4,398 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 83,856 KB
最終ジャッジ日時 2024-11-18 09:41:34
合計ジャッジ時間 19,690 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
56,916 KB
testcase_01 AC 46 ms
57,848 KB
testcase_02 AC 47 ms
56,856 KB
testcase_03 AC 1,356 ms
81,628 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 AC 82 ms
77,672 KB
testcase_11 WA -
testcase_12 AC 90 ms
77,648 KB
testcase_13 WA -
testcase_14 RE -
testcase_15 AC 126 ms
78,676 KB
testcase_16 RE -
testcase_17 WA -
testcase_18 AC 82 ms
77,768 KB
testcase_19 WA -
testcase_20 AC 80 ms
77,440 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 87 ms
77,748 KB
testcase_24 WA -
testcase_25 AC 88 ms
77,584 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 90 ms
77,624 KB
testcase_29 WA -
testcase_30 AC 90 ms
77,936 KB
testcase_31 WA -
testcase_32 AC 675 ms
80,072 KB
testcase_33 AC 1,186 ms
81,452 KB
testcase_34 AC 1,287 ms
83,856 KB
testcase_35 AC 684 ms
79,596 KB
testcase_36 AC 797 ms
79,984 KB
testcase_37 AC 1,124 ms
82,604 KB
testcase_38 AC 250 ms
77,804 KB
testcase_39 AC 633 ms
79,572 KB
testcase_40 AC 1,236 ms
83,068 KB
testcase_41 AC 820 ms
79,420 KB
testcase_42 AC 820 ms
80,320 KB
testcase_43 AC 172 ms
77,188 KB
testcase_44 AC 49 ms
57,872 KB
testcase_45 AC 375 ms
77,840 KB
testcase_46 AC 506 ms
78,448 KB
testcase_47 AC 487 ms
78,128 KB
testcase_48 AC 271 ms
77,712 KB
testcase_49 AC 77 ms
74,324 KB
testcase_50 AC 148 ms
77,380 KB
testcase_51 AC 532 ms
78,376 KB
testcase_52 AC 70 ms
72,128 KB
testcase_53 AC 562 ms
78,604 KB
testcase_54 AC 764 ms
79,144 KB
testcase_55 AC 224 ms
77,232 KB
testcase_56 AC 381 ms
77,956 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 find_zero(x0, x1, f):
    v0 = f(x0)
    if v0 == 0:
        return x0+1
    left = x0; right = x1+1
    while left+1 < right:
        mid = (left + right) >> 1
        if v0 * f(mid) >= 0:
            left = mid
        else:
            right = mid
    return right

def binary_search(f, L):
    left = 0; right = L
    while left+1 < right:
        mid = (left + right) >> 1
        if f(mid) < 0:
            left = mid
        else:
            right = mid
    return right

def line_polygon_intersection(p0, p1, qs):
    x0, y0 = p0; x1, y1 = p1
    dx = x1 - x0; dy = y1 - y0
    h = lambda p: (p[0] - x0)*dy - (p[1] - y0)*dx
    L = len(qs)

    i0 = i1 = -1

    v0 = h(qs[0])
    v1 = h(qs[L-1])
    if v0 == v1:
        v2 = h(qs[1])
        # assert v0 != v2
        if v0 < v2:
            i0 = L-1
        else:
            i1 = L-1
    else:
        v2 = h(qs[1])
        if v1 > v0 <= v2:
            i0 = 0
        elif v1 < v0 >= v2:
            i1 = 0
        else:
            g = lambda x: min((v1 - v0)*x/(L-1) + v0, h(qs[x]))
            i0 = binary_search(lambda x: g(x+1) - g(x), L-1)

    if i1 == -1:
        B = i0 - L
        k = binary_search(lambda x: h(qs[B+x]) - h(qs[B+x+1]), L)
        i1 = (i0 + k) % L
    else:
        B = i1 - L
        k = binary_search(lambda x: h(qs[B+x+1]) - h(qs[B+x]), L)
        i0 = (i1 + k) % L

    if h(qs[i0]) * h(qs[i1]) > 0:
        # a line and a polygon are disjoint
        return []

    # a vertex to the left side of a line: i0
    # a vertex to the right side of a line: i1

    f = lambda i: h(qs[i-L])
    k0 = find_zero(i1, i0 if i1 < i0 else i0+L, f) % L
    k1 = find_zero(i0, i1 if i0 < i1 else i1+L, f) % L
    # vertices to the left side of a line: k0, k0+1, ..., k1-2, k1-1
    # vertices to the right side of a line: k1, k1+1, ..., k0-2, k0-1
    if k0 == k1:
        return [k0]
    return [k0, k1]





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):

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

    ch = [convex_hull(star[p]) for p in range(2)]
    for p in range(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"
            xx,yy = ch[p][i+1]
            if line_polygon_intersection((x,y),(xx,yy),ch[p^1]):
                return "Yes"
    
    assert False


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

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