結果
問題 | No.274 The Wall |
ユーザー | convexineq |
提出日時 | 2020-12-19 23:58:58 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,329 bytes |
コンパイル時間 | 624 ms |
コンパイル使用メモリ | 81,588 KB |
実行使用メモリ | 565,304 KB |
最終ジャッジ日時 | 2023-10-21 09:42:01 |
合計ジャッジ時間 | 5,715 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,492 KB |
testcase_01 | AC | 34 ms
53,492 KB |
testcase_02 | AC | 33 ms
53,492 KB |
testcase_03 | AC | 500 ms
346,376 KB |
testcase_04 | AC | 34 ms
53,536 KB |
testcase_05 | AC | 34 ms
53,536 KB |
testcase_06 | AC | 33 ms
53,536 KB |
testcase_07 | AC | 33 ms
53,536 KB |
testcase_08 | AC | 32 ms
53,536 KB |
testcase_09 | AC | 32 ms
53,536 KB |
testcase_10 | AC | 32 ms
53,536 KB |
testcase_11 | MLE | - |
testcase_12 | AC | 96 ms
76,708 KB |
testcase_13 | AC | 48 ms
63,740 KB |
testcase_14 | AC | 88 ms
76,296 KB |
testcase_15 | AC | 114 ms
76,776 KB |
testcase_16 | AC | 371 ms
252,436 KB |
testcase_17 | AC | 359 ms
256,412 KB |
testcase_18 | AC | 361 ms
252,532 KB |
testcase_19 | AC | 127 ms
77,276 KB |
testcase_20 | AC | 137 ms
77,324 KB |
testcase_21 | AC | 138 ms
77,312 KB |
testcase_22 | AC | 144 ms
77,268 KB |
testcase_23 | AC | 142 ms
77,332 KB |
testcase_24 | AC | 139 ms
77,408 KB |
testcase_25 | AC | 142 ms
77,360 KB |
ソースコード
def SCC_Tarjan(g): n = len(g) order = [-1]*n # 負なら未処理、[0,n) ならpre-order, n ならvisited low = [0]*n ord_now = 0 parent = [-1]*n gp = [0]*n gp_num = 0 S = [] q = [] for i in range(n): if order[i] == -1: q.append(i) while q: v = q.pop() if v >= 0: if order[v] != -1: continue order[v] = low[v] = ord_now ord_now += 1 S.append(v) q.append(~v) for c in g[v]: if order[c] == -1: q.append(c) parent[c] = v else: low[v] = min(low[v], order[c]) else: v = ~v if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) if low[v] == order[v]: while True: w = S.pop() order[w] = n gp[w] = gp_num if w==v: break gp_num += 1 return gp class TwoSAT: def __init__(self, n): self._n = n self._answer = [False]*n self._g = [[] for _ in range(2*n)] def add_clause(self, i: int, f: bool, j: int, g: bool) -> None: self._g[2*i+1-f].append(2*j+g) self._g[2*j+1-g].append(2*i+f) def satisfiable(self) -> bool: scc_id = SCC_Tarjan(self._g) for i in range(self._n): if scc_id[2*i] == scc_id[2*i+1]: return False self._answer[i] = scc_id[2*i] < scc_id[2*i+1] return True def answer(self): return self._answer n,m = map(int,input().split()) lr = [list(map(int,input().split())) for _ in range(n)] g = TwoSAT(n) for i in range(n): li,ri = lr[i] lli,rri = m-1-ri,m-1-li for j in range(i+1,n): lj,rj = lr[j] if li <= rj and lj <= ri: g.add_clause(i,1,j,1) g.add_clause(i,0,j,0) if lli <= rj and lj <= rri: g.add_clause(i,1,j,0) g.add_clause(i,0,j,1) print("YES" if g.satisfiable() else "NO")