結果

問題 No.274 The Wall
ユーザー zundamo-tizundamo-ti
提出日時 2021-03-01 04:38:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 820 ms / 2,000 ms
コード長 1,230 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-14 03:32:31
合計ジャッジ時間 8,568 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 34 ms
10,752 KB
testcase_04 AC 32 ms
10,752 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 33 ms
10,880 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 32 ms
10,880 KB
testcase_10 AC 32 ms
10,752 KB
testcase_11 AC 37 ms
11,008 KB
testcase_12 AC 804 ms
11,136 KB
testcase_13 AC 37 ms
10,752 KB
testcase_14 AC 153 ms
10,880 KB
testcase_15 AC 354 ms
11,008 KB
testcase_16 AC 35 ms
11,136 KB
testcase_17 AC 38 ms
11,136 KB
testcase_18 AC 35 ms
11,136 KB
testcase_19 AC 640 ms
11,136 KB
testcase_20 AC 731 ms
11,136 KB
testcase_21 AC 759 ms
11,264 KB
testcase_22 AC 815 ms
11,264 KB
testcase_23 AC 820 ms
11,136 KB
testcase_24 AC 809 ms
11,136 KB
testcase_25 AC 807 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

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, color, now):
    color[x] = now
    for y in G[x]:
        if color[y] >= 0:
            if color[y] == now:
                return False
            continue
        if not dfs(y, G, color, 1 - now):
            return False
    return True

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)

    is_bipartite = True
    color = [-1] * N
    for x in range(N):
        if color[x] >= 0:
            continue
        if not dfs(x, G, color, 0):
            is_bipartite = False
    print("YES" if is_bipartite else "NO")

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