結果

問題 No.274 The Wall
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-25 17:25:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,359 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 11,184 KB
実行使用メモリ 235,492 KB
最終ジャッジ日時 2023-09-18 23:06:28
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,748 KB
testcase_01 AC 17 ms
8,344 KB
testcase_02 AC 17 ms
8,372 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SCC:
    def __init__(self, n):
        self.n = n
        self.g = [[] for i in range(n)]
        self.rg = [[] for i in range(n)]

    def add_edge(self, a, b):
        self.g[a].append(b)
        self.rg[b].append(a)

    def scc(self):
        def _dfs(v):
            used[v] = True
            for u in self.g[v]:
                if not used[u]:
                    _dfs(u)
            vs.append(v)

        def _rdfs(v, k):
            used[v] = True
            cmp[v] = k
            for u in self.rg[v]:
                if not used[u]:
                    _rdfs(u, k)
        vs = []
        cmp = [-1]*self.n

        used = [False]*self.n
        for v in range(self.n):
            if not used[v]:
                _dfs(v)

        k = -1
        used = [False]*self.n
        for v in reversed(vs):
            if not used[v]:
                k += 1
                _rdfs(v, k)
        return cmp

import sys
import io, os
sys.setrecursionlimit(10**9)
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
LR0 = []
LR1 = []
for i in range(n):
    l, r = map(int, input().split())
    LR0.append((l, r))
    LR1.append((m-1-r, m-1-l))

scc = SCC(2*n)
for i in range(n-1):
    for j in range(i+1, n):
        li0, ri0 = LR0[i]
        li1, ri1 = LR1[i]
        lj0, rj0 = LR0[j]
        lj1, rj1 = LR1[j]
        # 区間がかぶる場合を考える
        cnt = 0
        if min(ri0, rj0) >= max(li0, lj0):
            # ¬xi ∨ ¬xj
            # xi ⇒ ¬xj, xj ⇒ ¬xi
            scc.add_edge(i, n+j)
            scc.add_edge(j, n+i)
            cnt += 1
        if min(ri0, rj1) >= max(li0, lj1):
            # ¬xi ∨ xj
            # xi ⇒ xj, ¬xj ⇒ ¬xi
            scc.add_edge(i, j)
            scc.add_edge(n+j, n+i)
        if min(ri1, rj0) >= max(li1, lj0):
            # xi ∨ ¬xj
            # ¬xi ⇒ ¬xj, xj ⇒ xi
            scc.add_edge(n+i, n+j)
            scc.add_edge(j, i)
            cnt += 1
        if min(ri1, rj1) >= max(li1, lj1):
            # xi ∨ xj
            # ¬xi ⇒ xj, ¬xj ⇒ xi
            scc.add_edge(n+i, j)
            scc.add_edge(n+j, i)
            cnt += 1
        if cnt == 4:
            print('NO')
            exit()

cmp = scc.scc()
for i in range(n):
    if cmp[i] == cmp[n+i]:
        print('NO')
        exit()
print('YES')
0