結果

問題 No.274 The Wall
ユーザー behoma8behoma8
提出日時 2023-03-07 15:48:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 309,792 KB
最終ジャッジ日時 2023-10-18 05:31:09
合計ジャッジ時間 6,466 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,640 KB
testcase_01 AC 43 ms
55,644 KB
testcase_02 WA -
testcase_03 AC 334 ms
194,644 KB
testcase_04 AC 44 ms
55,640 KB
testcase_05 AC 43 ms
55,640 KB
testcase_06 AC 44 ms
55,640 KB
testcase_07 AC 43 ms
55,640 KB
testcase_08 AC 43 ms
55,640 KB
testcase_09 AC 44 ms
55,640 KB
testcase_10 AC 44 ms
55,640 KB
testcase_11 AC 838 ms
309,792 KB
testcase_12 AC 187 ms
77,128 KB
testcase_13 AC 59 ms
65,684 KB
testcase_14 AC 107 ms
76,628 KB
testcase_15 AC 148 ms
77,772 KB
testcase_16 AC 404 ms
159,688 KB
testcase_17 AC 371 ms
150,416 KB
testcase_18 AC 378 ms
154,900 KB
testcase_19 AC 184 ms
77,792 KB
testcase_20 AC 192 ms
77,932 KB
testcase_21 AC 202 ms
77,988 KB
testcase_22 AC 207 ms
77,980 KB
testcase_23 WA -
testcase_24 AC 207 ms
77,988 KB
testcase_25 AC 205 ms
77,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys
from collections import defaultdict
from collections import deque

INF = sys.maxsize
sys.setrecursionlimit( 10 ** 8 )

def alg_graph_scc( gs, rgs, n ):
    """
        gs: 隣接リスト
        rgs: 逆向き隣接リスト
    """
    order = []
    used = [0]*n
    group = [None]*n
    def dfs(s):
        used[s] = 1
        for t in gs[s]:
            if not used[t]:
                dfs(t)
        order.append(s)
    def rdfs(s, col):
        group[s] = col
        used[s] = 1
        for t in rgs[s]:
            if not used[t]:
                rdfs(t, col)
    for i in range(n):
        if not used[i]:
            dfs(i)
    used = [0]*n
    label = 0
    for s in reversed(order):
        if not used[s]:
            rdfs(s, label)
            label += 1
    return label, group


N, M = [ int(i) for i in input().split() ]
LR = [ [ int(i) for i in input().split() ] for _ in range( N ) ]
def solve():

    LRT = []
    for l, r in LR:
        LRT.append( ( M - 1 - l, M - 1 - r ) )

    gs = [[] for _ in range(2*N)]
    for i in range(N):
        l0, r0 = LR[i]
        for j in range(N):
            if i != j:
                l1, r1 = LRT[j]
                if not ( r0 < l1 or r1 < l0 ): # conflict
                    gs[i].append( j )
                    gs[N+j].append( N+i )
                l1, r1 = LR[j]
                if not( r0 < l1 or r1 < l0 ): # conflict
                    gs[i].append( N+j )
                    gs[N+j].append( i )
#    print( gs )
    label, group = alg_graph_scc( gs, gs, 2*N )
#    print( label, group )
    for i in range(N):
        if group[i] == group[i+N]:
            print( 'NO' )
            return
    print( 'YES' )

solve()
0