結果

問題 No.274 The Wall
ユーザー prin_kemkemprin_kemkem
提出日時 2023-05-11 21:53:38
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 3,015 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 927,432 KB
最終ジャッジ日時 2023-08-18 12:47:54
合計ジャッジ時間 5,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 161 ms
78,728 KB
testcase_02 AC 157 ms
78,564 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 #

from collections import defaultdict, deque, Counter
import copy
from itertools import combinations, permutations, product, accumulate, groupby
from heapq import heapify, heappop, heappush
import math
import bisect
from pprint import pprint
import sys
# sys.setrecursionlimit(700000)
input = lambda: sys.stdin.readline().rstrip('\n')
inf = float('inf')
mod1 = 10**9+7
mod2 = 998244353
def ceil_div(x, y): return -(-x//y)

#################################################

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 is_intersect(li, ri, lj, rj):
    if li > lj: li, ri, lj, rj = ri, rj, li, lj
    return lj <= ri

N, M = map(int, input().split())
blocks = [tuple(map(int, input().split())) for _ in range(N)]
clause = []
for i in range(N):
    li, ri = blocks[i]
    for j in range(i+1, N):
        lj, rj = blocks[j]
        if is_intersect(li, ri, lj, rj): clause.append((i, False, j, False))
        if is_intersect(li, ri, M-1-rj, M-1-lj): clause.append((i, False, j, True))
        if is_intersect(M-1-ri, M-1-li, lj, rj): clause.append((i, True, j, False))
        if is_intersect(M-1-ri, M-1-li, M-1-rj, M-1-lj): clause.append((i, True, j, True))
del blocks
ans = two_sat(N, clause)
print("YNEOS"[ans is None::2])
0