結果

問題 No.274 The Wall
ユーザー zundamo-tizundamo-ti
提出日時 2021-03-01 03:44:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 107,136 KB
最終ジャッジ日時 2024-04-14 03:30:22
合計ジャッジ時間 10,162 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 201 ms
43,008 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 574 ms
107,136 KB
testcase_12 AC 651 ms
11,264 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 513 ms
36,736 KB
testcase_17 AC 494 ms
35,712 KB
testcase_18 AC 506 ms
37,504 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 666 ms
11,264 KB
testcase_23 AC 664 ms
11,264 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

def crossing(M, b0, b1):
    l0, r0 = b0
    l1, r1 = b1
    if l1 <= r0 and l0 <= r1:
        return True
    l0, r0 = M - 1 - r0, M - 1 - l0
    if l1 <= r0 and l0 <= r1:
        return True
    return False

def dfs(x, G, visited, finished):
    visited[x] = True
    for y in G[x]:
        if visited[y]:
            if y == x:
                continue
            if not finished[y]:
                return True
            continue
        dfs(y, G, visited, finished)
    finished[x] = True
    return False

def main():
    N, M = map(int, readline().split())
    blocks = [tuple(map(int, readline().split())) for _ in range(N)]
    G = [[] for _ in range(N)]
    for i in range(N):
        for j in range(i + 1, N):
            if crossing(M, blocks[i], blocks[j]):
                G[i].append(j)
                G[j].append(i)

    visited = [False] * N
    finished = [False] * N
    for x in range(N):
        if finished[x]:
            continue
        if dfs(x, G, visited, finished):
            print("NO")
            return
    print("YES")

if __name__ == "__main__":
    main()
0