結果
問題 | No.274 The Wall |
ユーザー | N-noa21 |
提出日時 | 2024-06-08 00:08:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,335 bytes |
コンパイル時間 | 181 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 856,816 KB |
最終ジャッジ日時 | 2024-06-08 00:08:47 |
合計ジャッジ時間 | 5,821 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 45 ms
55,052 KB |
testcase_02 | AC | 41 ms
54,272 KB |
testcase_03 | RE | - |
testcase_04 | AC | 41 ms
54,528 KB |
testcase_05 | AC | 42 ms
53,888 KB |
testcase_06 | AC | 41 ms
53,888 KB |
testcase_07 | AC | 41 ms
54,144 KB |
testcase_08 | AC | 41 ms
53,888 KB |
testcase_09 | AC | 40 ms
54,144 KB |
testcase_10 | AC | 42 ms
53,888 KB |
testcase_11 | MLE | - |
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 | -- | - |
ソースコード
#https://tjkendev.github.io/procon-library/python/graph/2-sat.html from collections import deque def scc(N, G, RG): order = [] used = [0]*N def dfs(s): used[s] = 1 for 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]*N label = 0 order.reverse() for s in order: if group[s] != -1: continue que = deque([s]) group[s] = label while que: v = que.popleft() for w in RG[v]: if group[w] != -1: continue que.append(w) group[w] = label label += 1 return group # topological ordering N,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 = 1 def add_edge(i, neg_i, j, neg_j): #print(i,neg_i,j,neg_j) if neg_i: i0 = i+N; i1 = i else: i0 = i; i1 = i+N if neg_j: j0 = j+N; j1 = j else: 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) # check if the formula is satisfiable def check(group): for i in range(N): if group[i] == group[i+N]: return False return True # assign values to variables def assign(group): res = [0]*N for i in range(N): if group[i] > group[i+N]: res[i] = 1 return res l = [tuple(map(int, input().split())) for i in range(N)] for i in range(N): L1,R1 = l[i] r_R1,r_L1 = M+1-L1,M+1-R1 for j in range(i+1,N): L2,R2 = l[j] r_R2,r_L2 = M+1-L2,M+1-R2 #print(L1,R1,r_L1,r_R1,L2,R2,r_L2,r_R2) if L1<=L2<=R1 or L1<=R2<=R1: add_edge(i,0,j,1) add_edge(j,0,i,1) if r_L1<=L2<=r_R1 or r_L1<=R2<=r_R1: add_edge(i,1,j,1) add_edge(j,0,i,0) if L1<=r_L2<=R1 or L1<=r_R2<=R1: add_edge(i,0,j,0) add_edge(j,1,i,1) if r_L1<=r_L2<=r_R1 or r_L1<=r_R2<=r_R1: add_edge(i,1,j,0) add_edge(j,1,i,0) group = scc(2*N, G, RG) if check(group): print("YES") else: print("NO")