結果

問題 No.274 The Wall
ユーザー proriboneproribone
提出日時 2021-01-30 16:38:53
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,593 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 596,556 KB
最終ジャッジ日時 2023-09-10 12:47:28
合計ジャッジ時間 12,851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,324 KB
testcase_01 AC 72 ms
71,200 KB
testcase_02 AC 76 ms
71,416 KB
testcase_03 RE -
testcase_04 AC 105 ms
71,232 KB
testcase_05 AC 71 ms
71,328 KB
testcase_06 AC 72 ms
71,304 KB
testcase_07 AC 71 ms
71,124 KB
testcase_08 AC 73 ms
71,068 KB
testcase_09 AC 74 ms
71,200 KB
testcase_10 AC 74 ms
71,464 KB
testcase_11 TLE -
testcase_12 AC 443 ms
78,252 KB
testcase_13 AC 96 ms
75,920 KB
testcase_14 AC 131 ms
77,888 KB
testcase_15 AC 168 ms
78,704 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 203 ms
79,752 KB
testcase_20 AC 207 ms
79,568 KB
testcase_21 AC 215 ms
80,056 KB
testcase_22 AC 217 ms
79,976 KB
testcase_23 AC 217 ms
79,820 KB
testcase_24 AC 219 ms
79,776 KB
testcase_25 AC 226 ms
80,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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,input().split())
L,R=[],[]
for _ in range(n):
    l,r=map(int,input().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