結果

問題 No.274 The Wall
ユーザー chocoruskchocorusk
提出日時 2020-09-20 00:39:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,224 bytes
コンパイル時間 1,290 ms
コンパイル使用メモリ 86,580 KB
実行使用メモリ 78,636 KB
最終ジャッジ日時 2023-09-06 04:06:24
合計ジャッジ時間 4,692 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,704 KB
testcase_01 AC 70 ms
71,100 KB
testcase_02 AC 70 ms
71,060 KB
testcase_03 AC 76 ms
75,320 KB
testcase_04 AC 71 ms
70,784 KB
testcase_05 AC 65 ms
70,932 KB
testcase_06 AC 69 ms
71,160 KB
testcase_07 AC 69 ms
71,100 KB
testcase_08 AC 70 ms
70,720 KB
testcase_09 AC 68 ms
70,816 KB
testcase_10 AC 69 ms
71,124 KB
testcase_11 AC 73 ms
75,328 KB
testcase_12 AC 95 ms
76,588 KB
testcase_13 AC 84 ms
75,612 KB
testcase_14 AC 114 ms
77,600 KB
testcase_15 AC 133 ms
77,428 KB
testcase_16 AC 73 ms
75,436 KB
testcase_17 AC 73 ms
75,460 KB
testcase_18 AC 73 ms
75,748 KB
testcase_19 AC 158 ms
78,636 KB
testcase_20 AC 159 ms
78,292 KB
testcase_21 AC 164 ms
78,220 KB
testcase_22 AC 165 ms
78,148 KB
testcase_23 AC 166 ms
78,236 KB
testcase_24 AC 164 ms
78,148 KB
testcase_25 AC 165 ms
78,592 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]
        dame=0
        if not (r1<l2 or r2<l1):
            g[i].append(j+n)
            g[j].append(i+n)
            dame+=1
        if not (r1<m-1-r2 or m-1-l2<l1):
            g[i].append(j)
            g[j+n].append(i+n)
            dame+=1
        if dame==2:
            print("NO")
            exit()
        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