結果

問題 No.274 The Wall
ユーザー nebukuro09nebukuro09
提出日時 2016-10-20 23:31:51
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-05-02 05:45:41
合計ジャッジ時間 14,549 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 11 ms
6,272 KB
testcase_02 AC 11 ms
6,144 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 11 ms
6,144 KB
testcase_06 WA -
testcase_07 AC 11 ms
6,144 KB
testcase_08 AC 12 ms
6,144 KB
testcase_09 AC 11 ms
6,272 KB
testcase_10 AC 11 ms
6,272 KB
testcase_11 AC 17 ms
6,656 KB
testcase_12 AC 1,484 ms
6,784 KB
testcase_13 AC 24 ms
6,272 KB
testcase_14 AC 243 ms
6,400 KB
testcase_15 AC 621 ms
6,656 KB
testcase_16 AC 18 ms
6,656 KB
testcase_17 AC 22 ms
6,656 KB
testcase_18 AC 16 ms
6,784 KB
testcase_19 AC 1,156 ms
6,784 KB
testcase_20 AC 1,336 ms
6,784 KB
testcase_21 AC 1,388 ms
6,784 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1,487 ms
6,656 KB
testcase_25 AC 1,485 ms
6,656 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 = R2-N-1, L2-N-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
            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