結果

問題 No.274 The Wall
ユーザー tjaketjake
提出日時 2020-10-18 21:08:52
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,979 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 10,176 KB
最終ジャッジ日時 2023-09-28 12:06:36
合計ジャッジ時間 5,013 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,644 KB
testcase_01 AC 19 ms
8,696 KB
testcase_02 AC 20 ms
8,832 KB
testcase_03 AC 21 ms
9,096 KB
testcase_04 AC 20 ms
8,652 KB
testcase_05 AC 20 ms
8,740 KB
testcase_06 AC 20 ms
8,684 KB
testcase_07 AC 19 ms
8,728 KB
testcase_08 AC 20 ms
8,680 KB
testcase_09 AC 20 ms
8,668 KB
testcase_10 AC 20 ms
8,800 KB
testcase_11 AC 24 ms
9,664 KB
testcase_12 AC 425 ms
9,876 KB
testcase_13 AC 23 ms
8,892 KB
testcase_14 AC 71 ms
9,228 KB
testcase_15 AC 156 ms
9,600 KB
testcase_16 AC 22 ms
9,476 KB
testcase_17 AC 23 ms
9,408 KB
testcase_18 AC 22 ms
9,332 KB
testcase_19 AC 268 ms
9,896 KB
testcase_20 AC 313 ms
9,952 KB
testcase_21 AC 326 ms
10,096 KB
testcase_22 AC 349 ms
10,148 KB
testcase_23 AC 345 ms
10,072 KB
testcase_24 AC 346 ms
10,176 KB
testcase_25 AC 352 ms
10,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(10**5)
def scc(N, G, RG):
    order = []
    used = [0]*N
    def dfs(s):
        used[s] = 1
        for t in G[s]:
            if not used[t]:
                dfs(t)
        order.append(s)
    for i in range(N):
        if not used[i]:
            dfs(i)
    group = [-1]*N
    label = 0
    order.reverse()
    for s in order:
        if group[s] != -1:
            continue
        que = deque([s])
        group[s] = label
        while que:
            v = que.popleft()
            for w in RG[v]:
                if group[w] != -1:
                    continue
                que.append(w)
                group[w] = label
        label += 1
    return label, group
def solve():
    N, M = map(int, readline().split())
    S = [tuple(map(int, readline().split())) for i in range(N)]

    G = [[] for i in range(2*N)]
    RG = [[] for i in range(2*N)]
    def add_edge(i, neg_i, j, neg_j):
        if neg_i:
            i0 = i+N; i1 = i
        else:
            i0 = i; i1 = i+N
        if neg_j:
            j0 = j+N; j1 = j
        else:
            j0 = j; j1 = j+N
        G[i1].append(j0); RG[j0].append(i1)
        G[j1].append(i0); RG[i0].append(j1)

    for i in range(N):
        li, ri = S[i]
        for j in range(i+1, N):
            lj, rj = S[j]
            p = q = 0
            if (li <= rj and lj <= ri):
                add_edge(i, 0, j, 0)
                add_edge(i, 1, j, 1)
                p = 1
            if (li <= M-1-lj and M-1-rj <= ri):
                add_edge(i, 0, j, 1)
                add_edge(i, 1, j, 0)
                q = 1
            if p and q:
                write("NO\n")
                return
    _, group = scc(2*N, G, RG)

    ok = 1
    for i in range(N):
        if group[i] == group[i+N]:
            ok = 0
            break
    if ok:
        write("YES\n")
    else:
        write("NO\n")
solve()
0