結果

問題 No.274 The Wall
ユーザー proriboneproribone
提出日時 2021-01-30 16:58:06
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,665 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 600,604 KB
最終ジャッジ日時 2023-09-10 13:16:20
合計ジャッジ時間 10,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,980 KB
testcase_01 AC 71 ms
70,964 KB
testcase_02 AC 72 ms
70,976 KB
testcase_03 AC 741 ms
323,056 KB
testcase_04 AC 70 ms
71,152 KB
testcase_05 AC 71 ms
71,320 KB
testcase_06 AC 70 ms
70,980 KB
testcase_07 AC 71 ms
71,108 KB
testcase_08 AC 71 ms
71,340 KB
testcase_09 AC 72 ms
71,084 KB
testcase_10 AC 71 ms
70,980 KB
testcase_11 TLE -
testcase_12 AC 670 ms
77,172 KB
testcase_13 AC 97 ms
75,808 KB
testcase_14 AC 134 ms
77,276 KB
testcase_15 AC 159 ms
78,360 KB
testcase_16 AC 699 ms
310,564 KB
testcase_17 AC 668 ms
296,424 KB
testcase_18 AC 716 ms
320,996 KB
testcase_19 AC 196 ms
79,668 KB
testcase_20 AC 203 ms
79,496 KB
testcase_21 AC 207 ms
79,808 KB
testcase_22 AC 212 ms
78,956 KB
testcase_23 AC 211 ms
79,520 KB
testcase_24 AC 209 ms
79,268 KB
testcase_25 AC 218 ms
79,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.readline
sys.setrecursionlimit(10**9)

def SCC(G,N):
    rG=[[] for _ in range(N)]
    P=[]
    seen=[0]*N
    for v in range(N):
        for nv in G[v]:
            rG[nv].append(v)
            
    def dfs(G,v):
        seen[v]=1
        for nv in G[v]:
            if not seen[nv]:
                dfs(G,nv)
        P.append(v)
    
    def rdfs(G,v,C):
        seen[v]=1
        group[v]=C
        for nv in G[v]:
            if not seen[nv]:
                rdfs(G,nv,C)
    for v in range(N):
        if not seen[v]:
            dfs(G,v)
    
    seen=[0]*N
    group=[-1]*N
    C=0
    for v in P[::-1]:
        if not seen[v]:
            rdfs(rG,v,C)
            C+=1
            
    Size=max(group)+1
    return group,Size

def intersect(l1,r1,l2,r2):
    if r1<l2 or r2<l1:
        return False
    return True

n,m=map(int,read().split())
L,R=[],[]
for _ in range(n):
    l,r=map(int,read().split())
    L.append(l)
    R.append(r)

G=[[] for _ in range(2*n)]

for i in range(n):
    for j in range(i):
        l1,r1=L[i],R[i]
        l2,r2=L[j],R[j]
        if intersect(l1,r1,l2,r2):
            G[i].append(j+n)
            G[j].append(i+n)
        l2,r2=m-R[j]-1,m-L[j]-1
        if intersect(l1,r1,l2,r2):
            G[i].append(j)
            G[j+n].append(i+n)
        l1,r1=m-R[i]-1,m-L[i]-1
        if intersect(l1,r1,l2,r2):
            G[i+n].append(j)
            G[j+n].append(i)
        l2,r2=L[j],R[j]
        if intersect(l1,r1,l2,r2):
            G[i+n].append(j+n)
            G[j].append(i)

group,_=SCC(G,2*n)
for i in range(n):
    if group[i]==group[i+n]:
        print('NO')
        exit()
print('YES')
0