結果

問題 No.274 The Wall
ユーザー proriboneproribone
提出日時 2021-01-30 16:40:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,656 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 206,016 KB
最終ジャッジ日時 2023-09-10 12:48:43
合計ジャッジ時間 4,333 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,808 KB
testcase_01 AC 16 ms
8,444 KB
testcase_02 AC 17 ms
8,332 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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

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 (l1<=l2 and l2<=r1) or (l2<=l1 and l1<=r2):
            G[i].append(j+n)
            G[j].append(i+n)
        l2,r2=m-R[j]-1,m-L[j]-1
        if (l1<=l2 and l2<=r1) or (l2<=l1 and l1<=r2):
            G[i].append(j)
            G[j+n].append(i+n)
        l1,r1=m-R[i]-1,m-L[i]-1
        if (l1<=l2 and l2<=r1) or (l2<=l1 and l1<=r2):
            G[i+n].append(j)
            G[j+n].append(i)
        l2,r2=L[j],R[j]
        if (l1<=l2 and l2<=r1) or (l2<=l1 and l1<=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