結果

問題 No.274 The Wall
ユーザー nebukuro09nebukuro09
提出日時 2016-10-20 23:40:49
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,103 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-05-02 05:46:27
合計ジャッジ時間 13,760 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,144 KB
testcase_01 AC 10 ms
6,144 KB
testcase_02 AC 11 ms
6,144 KB
testcase_03 AC 16 ms
6,400 KB
testcase_04 AC 12 ms
6,144 KB
testcase_05 AC 11 ms
6,144 KB
testcase_06 AC 12 ms
6,272 KB
testcase_07 AC 11 ms
6,144 KB
testcase_08 AC 10 ms
6,144 KB
testcase_09 AC 11 ms
6,144 KB
testcase_10 AC 10 ms
6,144 KB
testcase_11 AC 16 ms
6,656 KB
testcase_12 AC 1,624 ms
6,656 KB
testcase_13 AC 24 ms
6,272 KB
testcase_14 AC 246 ms
6,400 KB
testcase_15 AC 629 ms
6,656 KB
testcase_16 AC 17 ms
6,528 KB
testcase_17 AC 21 ms
6,528 KB
testcase_18 AC 16 ms
6,656 KB
testcase_19 AC 1,183 ms
6,784 KB
testcase_20 AC 1,374 ms
6,784 KB
testcase_21 AC 1,414 ms
6,784 KB
testcase_22 WA -
testcase_23 AC 1,513 ms
6,656 KB
testcase_24 AC 1,510 ms
6,912 KB
testcase_25 AC 1,531 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, raw_input().split())
blocks = [map(int, raw_input().split()) for _ in xrange(N)]
rinsetsu = [[] for _ in xrange(N)]

for i in xrange(N):
    for j in xrange(i+1, N):
        L1, R1 = blocks[i]
        L2, R2 = blocks[j]
        L3, R3 = M-R2-1, M-L2-1
        b1 = L1 <= L2 <= R1 or L1 <= R2 <= R1
        b2 = L1 <= L3 <= R1 or L1 <= R3 <= R1
        if b1 and b2:
            print 'NO'
            exit()
        elif b1 or b2:
            rinsetsu[i].append(j)
            rinsetsu[j].append(i)

def dfs(start, color):
    color[start] = 0
    stack = [start]
    while len(stack) > 0:
        node = stack.pop()
        next_color = (color[node]+1)%2
        for next_node in rinsetsu[node]:
            if color[next_node] == -1:
                color[next_node] = next_color
                stack.append(next_node)
            elif color[next_node] != next_color:
                return False
    return color

color = [-1 for _ in xrange(N)]
for i in xrange(N):
    if color[i] == -1:
        color = dfs(i, color)
    if not color:
        print 'NO'
        exit()
print 'YES'
0