結果

問題 No.274 The Wall
ユーザー nebukuro09nebukuro09
提出日時 2016-10-20 23:40:58
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 1,103 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 76,800 KB
実行使用メモリ 80,000 KB
最終ジャッジ日時 2024-05-02 05:46:34
合計ジャッジ時間 5,574 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
75,264 KB
testcase_01 AC 87 ms
75,520 KB
testcase_02 AC 89 ms
75,264 KB
testcase_03 AC 117 ms
78,976 KB
testcase_04 AC 90 ms
75,776 KB
testcase_05 AC 92 ms
75,776 KB
testcase_06 AC 88 ms
75,520 KB
testcase_07 AC 87 ms
75,776 KB
testcase_08 AC 88 ms
75,648 KB
testcase_09 AC 88 ms
75,392 KB
testcase_10 AC 87 ms
75,648 KB
testcase_11 AC 107 ms
79,104 KB
testcase_12 AC 152 ms
79,360 KB
testcase_13 AC 104 ms
77,440 KB
testcase_14 AC 127 ms
78,208 KB
testcase_15 AC 160 ms
79,488 KB
testcase_16 AC 114 ms
78,848 KB
testcase_17 AC 134 ms
79,232 KB
testcase_18 AC 108 ms
78,976 KB
testcase_19 AC 186 ms
79,488 KB
testcase_20 AC 200 ms
79,616 KB
testcase_21 AC 200 ms
80,000 KB
testcase_22 WA -
testcase_23 AC 199 ms
79,488 KB
testcase_24 AC 203 ms
79,744 KB
testcase_25 AC 212 ms
79,744 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