結果

問題 No.274 The Wall
ユーザー netyo715netyo715
提出日時 2021-12-29 07:33:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 720 ms / 2,000 ms
コード長 1,662 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2024-04-14 12:05:14
合計ジャッジ時間 7,811 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 35 ms
11,264 KB
testcase_04 AC 31 ms
11,008 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 AC 39 ms
11,520 KB
testcase_12 AC 711 ms
12,032 KB
testcase_13 AC 36 ms
11,136 KB
testcase_14 AC 140 ms
11,136 KB
testcase_15 AC 311 ms
11,520 KB
testcase_16 AC 38 ms
11,520 KB
testcase_17 AC 37 ms
11,392 KB
testcase_18 AC 37 ms
11,520 KB
testcase_19 AC 566 ms
11,904 KB
testcase_20 AC 648 ms
11,776 KB
testcase_21 AC 673 ms
12,160 KB
testcase_22 AC 718 ms
11,904 KB
testcase_23 AC 720 ms
11,904 KB
testcase_24 AC 717 ms
12,032 KB
testcase_25 AC 720 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def scc(N, G, RG):
    order = []
    used = [0]*N
    group = [None]*N
    def dfs(s):
        used[s] = 1
        for t in G[s]:
            if not used[t]:
                dfs(t)
        order.append(s)
    def rdfs(s, col):
        group[s] = col
        used[s] = 1
        for t in RG[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

def main():
    N, M = map(int, input().split())
    B = [list(map(int, input().split())) for _ in range(N)]

    g = [[] for _ in range(N*2)]

    def check(L1, R1, L2, R2, i, j):
        # AT BT
        rL1 = M-R1-1
        rR1 = M-L1-1
        f1 = f2 = False
        if not (R1 < L2 or R2 < L1):
            f1 = True
        if not (rR1 < L2 or R2 < rL1):
            f2 = True

        if f1 and f2:
            return False

        if f1:
            g[i].append(j+N)
            g[i+N].append(j)
            g[j].append(i+N)
            g[j+N].append(i)
        
        if f2:
            g[i].append(j)
            g[i+N].append(j+N)
            g[j].append(i)
            g[j+N].append(i+N)

        return True

    for i in range(N):
        L1, R1 = B[i]
        for j in range(i+1, N):
            L2, R2 = B[j]
            if not check(L1, R1, L2, R2, i, j):
                print("NO")
                return
    
    _, nums = scc(N*2, g, g)
    for i in range(N):
        if nums[i] == nums[i+N]:
            print("NO")
            return
    print("YES")

main()
0