結果

問題 No.274 The Wall
ユーザー zundamo-tizundamo-ti
提出日時 2021-03-01 04:25:00
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,264 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 8,856 KB
最終ジャッジ日時 2023-07-26 13:31:23
合計ジャッジ時間 7,173 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,284 KB
testcase_01 AC 17 ms
7,952 KB
testcase_02 AC 17 ms
8,216 KB
testcase_03 AC 18 ms
8,336 KB
testcase_04 AC 18 ms
8,280 KB
testcase_05 AC 17 ms
8,200 KB
testcase_06 AC 16 ms
8,216 KB
testcase_07 AC 17 ms
8,232 KB
testcase_08 AC 16 ms
8,292 KB
testcase_09 AC 17 ms
8,288 KB
testcase_10 AC 17 ms
8,256 KB
testcase_11 AC 19 ms
8,576 KB
testcase_12 AC 690 ms
8,652 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 19 ms
8,576 KB
testcase_17 AC 20 ms
8,556 KB
testcase_18 AC 19 ms
8,508 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 660 ms
8,856 KB
testcase_23 AC 660 ms
8,804 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
    t0 = l1 <= r0 and l0 <= r1
    l0, r0 = M - 1 - r0, M - 1 - l0
    t1 = l1 <= r0 and l0 <= r1
    if t0 and t1:
        return "NG"
    if t0 or t1:
        return True
    return False

def dfs(x, G, visited, finished, parity):
    visited[x] = True
    for y in G[x]:
        if visited[y]:
            if not finished[y] and parity == 1:
                return True
            continue
        dfs(y, G, visited, finished, 1 - parity)
    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):
            t = crossing(M, blocks[i], blocks[j])
            if t == "NG":
                print("NO")
                return
            if t:
                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, 1):
            print('NO')
            return
    print('YES')

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