結果

問題 No.274 The Wall
ユーザー chocoruskchocorusk
提出日時 2020-09-19 22:25:02
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,106 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 659,452 KB
最終ジャッジ日時 2023-09-06 01:02:20
合計ジャッジ時間 8,154 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,392 KB
testcase_01 AC 71 ms
71,436 KB
testcase_02 AC 68 ms
71,544 KB
testcase_03 AC 613 ms
376,276 KB
testcase_04 AC 70 ms
71,320 KB
testcase_05 AC 69 ms
71,372 KB
testcase_06 AC 69 ms
71,388 KB
testcase_07 AC 68 ms
71,532 KB
testcase_08 AC 69 ms
71,568 KB
testcase_09 AC 72 ms
71,592 KB
testcase_10 AC 71 ms
71,368 KB
testcase_11 MLE -
testcase_12 AC 219 ms
76,884 KB
testcase_13 AC 83 ms
75,864 KB
testcase_14 AC 113 ms
78,024 KB
testcase_15 AC 129 ms
78,100 KB
testcase_16 AC 519 ms
261,664 KB
testcase_17 AC 515 ms
255,992 KB
testcase_18 AC 534 ms
266,908 KB
testcase_19 AC 154 ms
78,860 KB
testcase_20 AC 158 ms
78,304 KB
testcase_21 AC 156 ms
78,780 KB
testcase_22 AC 156 ms
78,288 KB
testcase_23 AC 160 ms
78,436 KB
testcase_24 AC 161 ms
78,480 KB
testcase_25 AC 161 ms
78,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

def scc(g):
    n=len(g)
    cmp=[0]*n
    ord=[-1]*n
    fin=[False]*n
    low=[0]*n
    visited=[]
    num=0
    k=0
    for x in range(n):
        if ord[x]!=-1:
            continue
        st=[~x, x]
        while st:
            v=st.pop()
            if v>=0:
                if ord[v]!=-1:
                    continue
                ord[v]=num
                low[v]=num
                num+=1
                visited.append(v)
                for w in g[v]:
                    if ord[w]==-1:
                        st.append(~w)
                        st.append(w)
            else:
                v=~v
                if fin[v]:
                    continue
                fin[v]=True
                for w in g[v]:
                    if ord[w]<ord[v]:
                        if ord[w]<low[v]:
                            low[v]=ord[w]
                    elif ord[w]<n:
                        if low[w]<low[v]:
                            low[v]=low[w]
                if ord[v]==low[v]:
                    while True:
                        w=visited.pop()
                        cmp[w]=k
                        ord[w]=n
                        if w==v:
                            break
                    k+=1
    cmp=[k-1-x for x in cmp]
    return (k, cmp)
n, m=map(int, readline().split())
lr=list(map(int, read().split()))
l=lr[::2]
r=lr[1::2]
g=[[] for _ in range(2*n)]
for i in range(n):
    l1, r1=l[i], r[i]
    for j in range(i):
        l2, r2=l[j], r[j]
        if not (r1<l2 or r2<l1):
            g[i].append(j+n)
            g[j].append(i+n)
        if not (r1<m-1-r2 or m-1-l2<l1):
            g[i].append(j)
            g[j+n].append(i+n)
        if not (m-1-l1<l2 or r2<m-1-r1):
            g[i+n].append(j+n)
            g[j].append(i)
        if not (m-1-l1<m-1-r2 or m-1-l2<m-1-r1):
            g[i+n].append(j)
            g[j+n].append(i)
k, cmp=scc(g)
for x in range(n):
    if cmp[x]==cmp[x+n]:
        print("NO")
        exit()
print("YES")
0