結果

問題 No.274 The Wall
ユーザー tjaketjake
提出日時 2020-10-18 20:55:07
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,728 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 592,748 KB
最終ジャッジ日時 2023-09-28 12:05:10
合計ジャッジ時間 8,265 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,176 KB
testcase_01 AC 75 ms
71,168 KB
testcase_02 AC 74 ms
71,156 KB
testcase_03 AC 672 ms
317,200 KB
testcase_04 AC 74 ms
71,080 KB
testcase_05 AC 75 ms
71,316 KB
testcase_06 AC 76 ms
71,176 KB
testcase_07 AC 75 ms
70,956 KB
testcase_08 AC 74 ms
71,080 KB
testcase_09 AC 73 ms
71,184 KB
testcase_10 AC 72 ms
71,104 KB
testcase_11 MLE -
testcase_12 AC 115 ms
76,780 KB
testcase_13 AC 86 ms
75,456 KB
testcase_14 AC 115 ms
78,160 KB
testcase_15 AC 140 ms
78,460 KB
testcase_16 AC 594 ms
284,532 KB
testcase_17 AC 570 ms
271,688 KB
testcase_18 AC 623 ms
295,180 KB
testcase_19 AC 170 ms
79,460 KB
testcase_20 AC 181 ms
79,564 KB
testcase_21 AC 179 ms
79,436 KB
testcase_22 AC 181 ms
79,484 KB
testcase_23 AC 180 ms
79,396 KB
testcase_24 AC 183 ms
79,520 KB
testcase_25 AC 186 ms
79,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(10**5)
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
    order.reverse()
    for s in order:
        if not used[s]:
            rdfs(s, 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]
            if (li <= rj and lj <= ri):
                add_edge(i, 0, j, 0)
                add_edge(i, 1, j, 1)
            if (li <= M-1-lj and M-1-rj <= ri):
                add_edge(i, 0, j, 1)
                add_edge(i, 1, j, 0)
    label, 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