結果

問題 No.274 The Wall
ユーザー convexineqconvexineq
提出日時 2021-02-22 04:54:34
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,329 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 81,740 KB
実行使用メモリ 564,840 KB
最終ジャッジ日時 2023-10-20 05:18:56
合計ジャッジ時間 7,522 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,500 KB
testcase_01 AC 38 ms
53,500 KB
testcase_02 AC 39 ms
53,500 KB
testcase_03 AC 587 ms
346,460 KB
testcase_04 AC 100 ms
53,504 KB
testcase_05 AC 39 ms
53,504 KB
testcase_06 AC 39 ms
53,504 KB
testcase_07 AC 39 ms
53,504 KB
testcase_08 AC 39 ms
53,504 KB
testcase_09 AC 38 ms
53,504 KB
testcase_10 AC 38 ms
53,504 KB
testcase_11 MLE -
testcase_12 AC 212 ms
76,772 KB
testcase_13 AC 53 ms
63,728 KB
testcase_14 AC 91 ms
76,320 KB
testcase_15 AC 123 ms
76,844 KB
testcase_16 AC 409 ms
252,500 KB
testcase_17 AC 382 ms
256,472 KB
testcase_18 AC 393 ms
252,600 KB
testcase_19 AC 142 ms
77,332 KB
testcase_20 AC 149 ms
77,396 KB
testcase_21 AC 152 ms
77,376 KB
testcase_22 AC 146 ms
77,352 KB
testcase_23 AC 155 ms
77,400 KB
testcase_24 AC 147 ms
77,480 KB
testcase_25 AC 148 ms
77,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def SCC_Tarjan(g):
    n = len(g)
    order = [-1]*n # 負なら未処理、[0,n) ならpre-order, n ならvisited
    low = [0]*n
    ord_now = 0
    parent = [-1]*n
    gp = [0]*n
    gp_num = 0
    S = []
    q = []
    for i in range(n):
        if order[i] == -1:
            q.append(i)
            while q:
                v = q.pop()
                if v >= 0:
                    if order[v] != -1: continue
                    order[v] = low[v] = ord_now
                    ord_now += 1
                    S.append(v)
                    q.append(~v)
                    for c in g[v]:
                        if order[c] == -1: 
                            q.append(c)
                            parent[c] = v
                        else:
                            low[v] = min(low[v], order[c])
                else:
                    v = ~v
                    if parent[v] != -1:
                        low[parent[v]] = min(low[parent[v]], low[v])
                    if low[v] == order[v]:
                        while True:
                            w = S.pop()
                            order[w] = n
                            gp[w] = gp_num
                            if w==v: break
                        gp_num += 1
 
    return gp

class TwoSAT:
    def __init__(self, n):
        self._n = n
        self._answer = [False]*n
        self._g = [[] for _ in range(2*n)]

    def add_clause(self, i: int, f: bool, j: int, g: bool) -> None:
        self._g[2*i+1-f].append(2*j+g)
        self._g[2*j+1-g].append(2*i+f)

    def satisfiable(self) -> bool:
        scc_id = SCC_Tarjan(self._g)
        for i in range(self._n):
            if scc_id[2*i] == scc_id[2*i+1]:
                return False
            self._answer[i] = scc_id[2*i] < scc_id[2*i+1]
        return True

    def answer(self):
        return self._answer



n,m = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(n)]
g = TwoSAT(n)
for i in range(n):
    li,ri = lr[i]
    lli,rri = m-1-ri,m-1-li
    for j in range(i+1,n):
        lj,rj = lr[j]
        if li <= rj and lj <= ri:
            g.add_clause(i,1,j,1)
            g.add_clause(i,0,j,0)
        if lli <= rj and lj <= rri:
            g.add_clause(i,1,j,0)
            g.add_clause(i,0,j,1)

print("YES" if g.satisfiable() else "NO")
0