結果

問題 No.274 The Wall
ユーザー yaoshimax
提出日時 2016-05-11 23:33:00
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 1,183 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 76,964 KB
実行使用メモリ 80,288 KB
最終ジャッジ日時 2025-03-17 18:50:56
合計ジャッジ時間 6,871 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,raw_input().split())
lines=[]
blocked=[False for i in range(M)]
used=[False for i in range(N)]
for i in range(N):
    L,R=map(int,raw_input().split())
    lines.append(((L,R),(M-R-1,M-L-1)))

useCnt=0
while useCnt < N:
    toCheck=[]
    for i in range(N):
        if used[i]==False:
            toCheck.append((i,0))
            used[i]=True
            break
    while len(toCheck)!=0:
        p,q=toCheck[0]
        toCheck.pop(0)
        l,r=lines[p][q]
        useCnt+=1
        for c in range(l,r+1):
            if blocked[c]==True:
                print "NO"
                exit()
            blocked[c]=True
            for t in range(N):
                if used[t]==False:
                    if lines[t][0][0]<=c and lines[t][0][1]>=c and lines[t][1][0]<=c and lines[t][1][1]>=c:
                        print "NO"
                        exit()
                    elif lines[t][0][0]<=c and lines[t][0][1]>=c :
                        toCheck.append((t,1))
                        used[t]=True
                    elif lines[t][1][0]<=c and lines[t][1][1]>=c :
                        toCheck.append((t,0))
                        used[t]=True
print "YES"

0