結果
問題 | No.274 The Wall |
ユーザー | vwxyz |
提出日時 | 2023-05-17 10:05:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 385 ms / 2,000 ms |
コード長 | 3,186 bytes |
コンパイル時間 | 2,088 ms |
コンパイル使用メモリ | 86,620 KB |
実行使用メモリ | 79,952 KB |
最終ジャッジ日時 | 2023-08-21 16:18:14 |
合計ジャッジ時間 | 7,530 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
71,260 KB |
testcase_01 | AC | 71 ms
70,988 KB |
testcase_02 | AC | 71 ms
71,328 KB |
testcase_03 | AC | 80 ms
76,480 KB |
testcase_04 | AC | 71 ms
70,972 KB |
testcase_05 | AC | 73 ms
71,336 KB |
testcase_06 | AC | 72 ms
70,972 KB |
testcase_07 | AC | 72 ms
71,240 KB |
testcase_08 | AC | 70 ms
71,384 KB |
testcase_09 | AC | 71 ms
71,192 KB |
testcase_10 | AC | 72 ms
71,236 KB |
testcase_11 | AC | 82 ms
76,304 KB |
testcase_12 | AC | 309 ms
78,032 KB |
testcase_13 | AC | 88 ms
75,980 KB |
testcase_14 | AC | 162 ms
77,952 KB |
testcase_15 | AC | 246 ms
79,200 KB |
testcase_16 | AC | 82 ms
76,800 KB |
testcase_17 | AC | 82 ms
76,504 KB |
testcase_18 | AC | 81 ms
76,504 KB |
testcase_19 | AC | 331 ms
79,524 KB |
testcase_20 | AC | 350 ms
79,276 KB |
testcase_21 | AC | 360 ms
79,772 KB |
testcase_22 | AC | 375 ms
79,520 KB |
testcase_23 | AC | 377 ms
79,620 KB |
testcase_24 | AC | 385 ms
79,952 KB |
testcase_25 | AC | 377 ms
79,776 KB |
ソースコード
import sys readline=sys.stdin.readline def SCC(N,edges): start = [0] * (N + 1) elist = [0] * len(edges) 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 N = N now_ord = group_num = 0 visited = [] low = [0] * N order = [-1] * N ids = [0] * N parent = [-1] * N stack = [] for i in range(N): if order[i] == -1: stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(start[v], start[v + 1]): to = elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v], order[to]) else: if low[v] == order[v]: while True: u = visited.pop() order[u] = N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups class TwoSAT: def __init__(self,N): self.N=N self.edges=[] def Add_Clause(self,i,f,j,g): assert 0<=i<self.N assert 0<=j<self.N self.edges.append((2*i+(0 if f else 1),2*j+(1 if g else 0))) self.edges.append((2*j+(0 if g else 1),2*i+(1 if f else 0))) def Satisfiable(self): scc=SCC(2*self.N,self.edges) idx=[None]*2*self.N for i,lst in enumerate(scc): for x in lst: idx[x]=i retu=[None]*self.N for i in range(self.N): if idx[2*i]==idx[2*i+1]: return None retu[i]=idx[2*i]<idx[2*i+1] return retu N,M=map(int,readline().split()) L,R=[],[] for n in range(N): l,r=map(int,readline().split()) r+=1 L.append(l) R.append(r) if sum(r-l for l,r in zip(L,R))>M: print("NO") exit() TSAT=TwoSAT(N) for i in range(N): for j in range(i+1,N): for bi in (0,1): if bi==0: li,ri=L[i],R[i] else: li,ri=M-R[i],M-L[i] for bj in (0,1): if bj==0: lj,rj=L[j],R[j] else: lj,rj=M-R[j],M-L[j] if max(li,lj)<min(ri,rj): TSAT.Add_Clause(i,bi,j,bj) if TSAT.Satisfiable(): ans="YES" else: ans="NO" print(ans)