結果

問題 No.274 The Wall
ユーザー brthyyjpbrthyyjp
提出日時 2023-06-05 22:49:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 3,069 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 11,228 KB
実行使用メモリ 496,256 KB
最終ジャッジ日時 2023-08-28 09:46:13
合計ジャッジ時間 4,979 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
13,008 KB
testcase_01 AC 17 ms
8,512 KB
testcase_02 AC 16 ms
8,636 KB
testcase_03 TLE -
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 #

# https://github.com/shakayami/ACL-for-python/blob/master/two_sat.py

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

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
LR0 = []
LR1 = []
for i in range(n):
    l, r = map(int, input().split())
    LR0.append((l, r))
    LR1.append((m-1-r, m-1-l))

clause = []
for i in range(n-1):
    for j in range(i+1, n):
        li0, ri0 = LR0[i]
        li1, ri1 = LR1[i]
        lj0, rj0 = LR0[j]
        lj1, rj1 = LR1[j]
        # 区間がかぶる場合を考える
        if min(ri0, rj0) >= max(li0, lj0):
            # ¬xi ∨ ¬xj
            # xi ⇒ ¬xj, xj ⇒ ¬xi
            clause.append((i, False, j, False))
        if min(ri0, rj1) >= max(li0, lj1):
            # ¬xi ∨ xj
            # xi ⇒ xj, ¬xj ⇒ ¬xi
            clause.append((i, False, j, True))
        if min(ri1, rj0) >= max(li1, lj0):
            # xi ∨ ¬xj
            # ¬xi ⇒ ¬xj, xj ⇒ xi
            clause.append((i, True, j, False))
        if min(ri1, rj1) >= max(li1, lj1):
            # xi ∨ xj
            # ¬xi ⇒ xj, ¬xj ⇒ xi
            clause.append((i, True, j, True))

ans = two_sat(n, clause)
if ans is not None:
    print('YES')
else:
    print('NO')
0