結果

問題 No.274 The Wall
ユーザー 👑 H20H20
提出日時 2022-03-07 12:45:46
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,590 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 850,016 KB
最終ジャッジ日時 2023-09-29 12:19:41
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
71,288 KB
testcase_01 AC 57 ms
71,440 KB
testcase_02 AC 56 ms
71,412 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 #

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

N,M = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(N)]
clause=[]
for i in range(N):
    for j in range(i+1,N):
        IFl = LR[i][0]
        IFr = LR[i][1]
        JFl = LR[j][0]
        JFr = LR[j][1]
        IBl = M-LR[i][1]-1
        IBr = M-LR[i][0]-1
        JBl = M-LR[j][1]-1
        JBr = M-LR[j][0]-1

        if (IFl <= JFr and JFl <= IFr):
            clause.append((i,True,j,True))
        if (IFl <= JBr and JBl <= IFr):
            clause.append((i,True,j,False))
        if (IBl <= JFr and JFl <= IBr):
            clause.append((i,False,j,True))
        if (IBl <= JBr and JBl <= IBr):
            clause.append((i,False,j,False))

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