結果
問題 | No.274 The Wall |
ユーザー |
![]() |
提出日時 | 2023-11-24 23:30:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 176 ms / 2,000 ms |
コード長 | 2,062 bytes |
コンパイル時間 | 515 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 79,616 KB |
最終ジャッジ日時 | 2024-09-26 09:49:03 |
合計ジャッジ時間 | 3,768 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
from collections import dequeimport syssys.setrecursionlimit(10**7)def scc(N, G, RG):order = []used = [0]*Ndef dfs(s):used[s] = 1for t in G[s]:if not used[t]:dfs(t)order.append(s)for i in range(N):if not used[i]:dfs(i)group = [-1]*Nlabel = 0order.reverse()for s in order:if group[s] != -1:continueque = deque([s])group[s] = labelwhile que:v = que.popleft()for w in RG[v]:if group[w] != -1:continueque.append(w)group[w] = labellabel += 1return group # topological orderingN,M=map(int, input().split())G = [[] for i in range(2*N)]RG = [[] for i in range(2*N)]# add (a ∨ b)# a = x_i if neg_i = 0# a = ~x_i if neg_i = 1def add_edge(i, neg_i, j, neg_j):if neg_i:i0 = i+N; i1 = ielse:i0 = i; i1 = i+Nif neg_j:j0 = j+N; j1 = jelse:j0 = j; j1 = j+N# add (~a ⇒ b)G[i1].append(j0); RG[j0].append(i1)# add (~b ⇒ a)G[j1].append(i0); RG[i0].append(j1)group = scc(2*N, G, RG)# check if the formula is satisfiabledef check(group):for i in range(N):if group[i] == group[i+N]:return Falsereturn True# assign values to variablesdef assign(group):res = [0]*Nfor i in range(N):if group[i] > group[i+N]:res[i] = 1return resA=[]for i in range(N):x,y=map(int, input().split())A.append((x,y))for i in range(N-1):for j in range(i+1,N):al,ar=A[i];bl,br=A[j]p,q=0,0if al<=br and bl<=ar:add_edge(i,1,j,1)add_edge(i,0,j,0)p=1cl,cr=M-1-br,M-1-blif al<=cr and cl<=ar:add_edge(i,0,j,1)add_edge(i,1,j,0)q=1if p+q==2:print('NO')exit()#print(G,RG)A=scc(2*N,G,RG)for i in range(N):if A[i]==A[i+N]:print('NO')exit()print('YES')