結果

問題 No.274 The Wall
ユーザー proriboneproribone
提出日時 2021-01-30 17:02:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 80,664 KB
最終ジャッジ日時 2023-09-10 13:20:39
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,120 KB
testcase_01 AC 74 ms
71,340 KB
testcase_02 AC 71 ms
71,204 KB
testcase_03 AC 94 ms
76,520 KB
testcase_04 AC 72 ms
71,048 KB
testcase_05 AC 71 ms
71,208 KB
testcase_06 AC 70 ms
71,276 KB
testcase_07 AC 70 ms
71,372 KB
testcase_08 AC 73 ms
71,132 KB
testcase_09 AC 72 ms
71,268 KB
testcase_10 AC 72 ms
71,024 KB
testcase_11 AC 95 ms
76,496 KB
testcase_12 AC 163 ms
78,112 KB
testcase_13 AC 101 ms
75,912 KB
testcase_14 AC 138 ms
78,316 KB
testcase_15 AC 186 ms
79,776 KB
testcase_16 AC 96 ms
76,760 KB
testcase_17 AC 95 ms
76,740 KB
testcase_18 AC 96 ms
76,756 KB
testcase_19 AC 215 ms
80,196 KB
testcase_20 AC 220 ms
79,772 KB
testcase_21 AC 225 ms
79,844 KB
testcase_22 AC 254 ms
80,256 KB
testcase_23 AC 236 ms
80,024 KB
testcase_24 AC 229 ms
80,224 KB
testcase_25 AC 249 ms
80,664 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())
blocks=[tuple(map(int,input().split())) for _ in range(n)]

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

for i in range(n):
    for j in range(i):
        c=0
        l1,r1=blocks[i]
        l2,r2=blocks[j]
        if intersect(l1,r1,l2,r2):
            G[i].append(j+n)
            G[j].append(i+n)
            c+=1
        l2,r2=m-r2-1,m-l2-1
        if intersect(l1,r1,l2,r2):
            G[i].append(j)
            G[j+n].append(i+n)
            c+=1
        l1,r1=m-r1-1,m-l1-1
        if intersect(l1,r1,l2,r2):
            G[i+n].append(j)
            G[j+n].append(i)
            c+=1
        l2,r2=m-r2-1,m-l2-1
        if intersect(l1,r1,l2,r2):
            G[i+n].append(j+n)
            G[j].append(i)
            c+=1
        if c==4:
            print('NO')
            exit()

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