結果

問題 No.274 The Wall
ユーザー roarisroaris
提出日時 2019-12-06 15:13:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,319 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 79,032 KB
最終ジャッジ日時 2023-09-04 02:46:11
合計ジャッジ時間 5,912 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,624 KB
testcase_01 AC 92 ms
71,520 KB
testcase_02 AC 93 ms
71,624 KB
testcase_03 AC 118 ms
78,068 KB
testcase_04 AC 92 ms
71,484 KB
testcase_05 AC 92 ms
71,328 KB
testcase_06 AC 92 ms
71,536 KB
testcase_07 AC 92 ms
71,500 KB
testcase_08 AC 93 ms
71,484 KB
testcase_09 AC 94 ms
71,396 KB
testcase_10 AC 94 ms
71,612 KB
testcase_11 AC 118 ms
77,716 KB
testcase_12 AC 166 ms
78,272 KB
testcase_13 AC 116 ms
76,836 KB
testcase_14 AC 154 ms
77,744 KB
testcase_15 AC 187 ms
78,788 KB
testcase_16 AC 122 ms
77,868 KB
testcase_17 AC 122 ms
77,896 KB
testcase_18 AC 121 ms
77,788 KB
testcase_19 AC 213 ms
78,964 KB
testcase_20 AC 225 ms
78,800 KB
testcase_21 AC 230 ms
78,984 KB
testcase_22 AC 205 ms
78,576 KB
testcase_23 AC 217 ms
78,568 KB
testcase_24 AC 235 ms
78,936 KB
testcase_25 AC 237 ms
79,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def bfs(s):
    q = deque([])
    q.append((s, 1))
    
    while q:
        v, c = q.popleft()
        
        for nv in adj_list[v]:
            if color[nv]==-1:
                color[nv] = -c
                q.append((nv, color[nv]))
            else:
                if color[nv]==c:
                    return False
    
    return True

N, M = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(N)]
adj_list = [[] for _ in range(N)]

for i in range(N):
    Li, Ri = LR[i]
    
    for j in range(i+1, N):
        Lj, Rj = LR[j]
        a, b, c, d = Li, Ri, Lj, Rj
        
        if a>c:
            a, b, c, d = c, d, a, b
        
        if not b<c:
            flag1 = True
        else:
            flag1 = False
        
        Lj, Rj = M-1-Rj, M-1-Lj
        a, b, c, d = Li, Ri, Lj, Rj
        
        if a>c:
            a, b, c, d = c, d, a, b
        
        if not b<c:
            flag2 = True
        else:
            flag2 = False
            
        if flag1 and flag2:
            print('NO')
            exit()
        elif flag1 or flag2:
            adj_list[i].append(j)
            adj_list[j].append(i)

for i in range(N):
    color = [-1]*N
    
    if not bfs(i):
        print('NO')
        break
else:
    print('YES')
0