結果

問題 No.274 The Wall
ユーザー とりゐとりゐ
提出日時 2023-04-02 01:40:44
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,513 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,796 KB
実行使用メモリ 849,168 KB
最終ジャッジ日時 2024-04-10 10:03:45
合計ジャッジ時間 4,098 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,420 KB
testcase_01 AC 40 ms
52,988 KB
testcase_02 AC 36 ms
53,036 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]

def two_sat(n,clause):
    answer=[0]*n
    edges=[]
    N=2*n
    for s in clause:
        i,f,j,g=s
        edges.append((2*i+(0 if f else 1),2*j+(1 if g else 0)))
        edges.append((2*j+(0 if g else 1),2*i+(1 if f else 0)))
    M=len(edges)
    start=[0]*(N+1)
    elist=[0]*M
    for e in edges:
        start[e[0]+1]+=1
    for i in range(1,N+1):
        start[i]+=start[i-1]
    counter=start[:]
    for e in edges:
        elist[counter[e[0]]]=e[1]
        counter[e[0]]+=1
    visited=[]
    low=[0]*N
    Ord=[-1]*N
    ids=[0]*N
    NG=[0,0]
    def dfs(v):
        stack=[(v,-1,0),(v,-1,1)]
        while stack:
            v,bef,t=stack.pop()
            if t:
                if bef!=-1 and Ord[v]!=-1:
                    low[bef]=min(low[bef],Ord[v])
                    stack.pop()
                    continue
                low[v]=NG[0]
                Ord[v]=NG[0]
                NG[0]+=1
                visited.append(v)
                for i in range(start[v],start[v+1]):
                    to=elist[i]
                    if Ord[to]==-1:
                        stack.append((to,v,0))
                        stack.append((to,v,1))
                    else:
                        low[v]=min(low[v],Ord[to])
            else:
                if low[v]==Ord[v]:
                    while(True):
                        u=visited.pop()
                        Ord[u]=N
                        ids[u]=NG[1]
                        if u==v:
                            break
                    NG[1]+=1
                low[bef]=min(low[bef],low[v])
    for i in range(N):
        if Ord[i]==-1:
            dfs(i)
    for i in range(N):
        ids[i]=NG[1]-1-ids[i]
    for i in range(n):
        if ids[2*i]==ids[2*i+1]:
            return None
        answer[i]=(ids[2*i]<ids[2*i+1])
    return answer

def ok(l1,r1,l2,r2):
  if r1<l2 or r2<l1:
    return True
  return False

n,m=map(int,input().split())
m-=1
clauses=[]
LR=[]
for i in range(n):
  l,r=map(int,input().split())
  LR.append((l,r))
for i in range(n):
  for j in range(i+1,n):
    li,ri=LR[i]
    lj,rj=LR[j]
    if not ok(li,ri,lj,rj):
      clauses.append((i,False,j,False))
    if not ok(li,ri,m-rj,m-lj):
      clauses.append((i,False,j,True))
    if not ok(m-ri,m-li,lj,rj):
      clauses.append((i,True,j,False))
    if not ok(m-ri,m-li,m-rj,m-lj):
      clauses.append((i,True,j,True))

ans=two_sat(n,clauses)
if ans:
  print('YES')
else:
  print('NO')
0