結果

問題 No.274 The Wall
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-25 17:28:35
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,359 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 625,600 KB
最終ジャッジ日時 2023-09-18 23:06:51
合計ジャッジ時間 9,060 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,388 KB
testcase_01 AC 69 ms
71,448 KB
testcase_02 AC 69 ms
71,612 KB
testcase_03 RE -
testcase_04 AC 71 ms
71,320 KB
testcase_05 AC 70 ms
71,136 KB
testcase_06 AC 69 ms
71,416 KB
testcase_07 AC 70 ms
71,284 KB
testcase_08 AC 72 ms
71,176 KB
testcase_09 AC 71 ms
71,348 KB
testcase_10 AC 70 ms
71,316 KB
testcase_11 MLE -
testcase_12 AC 130 ms
77,548 KB
testcase_13 AC 93 ms
76,108 KB
testcase_14 AC 122 ms
78,140 KB
testcase_15 AC 156 ms
78,592 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 196 ms
80,028 KB
testcase_20 AC 213 ms
80,124 KB
testcase_21 AC 207 ms
79,684 KB
testcase_22 AC 208 ms
80,240 KB
testcase_23 AC 207 ms
79,984 KB
testcase_24 AC 211 ms
79,884 KB
testcase_25 AC 225 ms
79,980 KB
権限があれば一括ダウンロードができます

ソースコード

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**3)
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