結果

問題 No.274 The Wall
ユーザー proriboneproribone
提出日時 2021-01-30 16:39:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,656 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 596,296 KB
最終ジャッジ日時 2023-09-10 12:48:12
合計ジャッジ時間 10,490 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,264 KB
testcase_01 AC 72 ms
71,076 KB
testcase_02 AC 72 ms
71,352 KB
testcase_03 AC 744 ms
313,824 KB
testcase_04 AC 73 ms
71,600 KB
testcase_05 AC 73 ms
71,596 KB
testcase_06 AC 72 ms
71,376 KB
testcase_07 AC 74 ms
71,308 KB
testcase_08 AC 73 ms
71,604 KB
testcase_09 AC 73 ms
71,504 KB
testcase_10 AC 72 ms
71,260 KB
testcase_11 TLE -
testcase_12 AC 374 ms
77,476 KB
testcase_13 AC 93 ms
75,868 KB
testcase_14 AC 123 ms
78,080 KB
testcase_15 AC 153 ms
78,476 KB
testcase_16 AC 997 ms
305,984 KB
testcase_17 AC 962 ms
307,240 KB
testcase_18 AC 1,031 ms
316,204 KB
testcase_19 AC 183 ms
79,228 KB
testcase_20 AC 191 ms
79,088 KB
testcase_21 AC 196 ms
79,096 KB
testcase_22 AC 201 ms
79,788 KB
testcase_23 AC 201 ms
78,976 KB
testcase_24 AC 200 ms
79,072 KB
testcase_25 AC 212 ms
80,068 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

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