結果

問題 No.274 The Wall
ユーザー netyo715netyo715
提出日時 2021-12-29 07:30:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 266,240 KB
最終ジャッジ日時 2024-04-14 11:49:35
合計ジャッジ時間 4,931 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 and 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", i, j)
                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