結果
問題 | No.274 The Wall |
ユーザー | convexineq |
提出日時 | 2021-02-22 04:54:34 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,329 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 565,860 KB |
最終ジャッジ日時 | 2024-09-20 01:00:46 |
合計ジャッジ時間 | 6,081 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,480 KB |
testcase_01 | AC | 40 ms
52,608 KB |
testcase_02 | AC | 37 ms
52,864 KB |
testcase_03 | AC | 530 ms
357,004 KB |
testcase_04 | AC | 37 ms
52,864 KB |
testcase_05 | AC | 37 ms
52,352 KB |
testcase_06 | AC | 35 ms
52,864 KB |
testcase_07 | AC | 37 ms
52,224 KB |
testcase_08 | AC | 36 ms
52,352 KB |
testcase_09 | AC | 37 ms
52,608 KB |
testcase_10 | AC | 37 ms
52,480 KB |
testcase_11 | MLE | - |
testcase_12 | AC | 102 ms
77,568 KB |
testcase_13 | AC | 51 ms
62,336 KB |
testcase_14 | AC | 92 ms
76,672 KB |
testcase_15 | AC | 125 ms
77,568 KB |
testcase_16 | AC | 413 ms
252,900 KB |
testcase_17 | AC | 423 ms
257,028 KB |
testcase_18 | AC | 376 ms
257,488 KB |
testcase_19 | AC | 142 ms
77,756 KB |
testcase_20 | AC | 149 ms
78,192 KB |
testcase_21 | AC | 152 ms
77,976 KB |
testcase_22 | AC | 145 ms
78,124 KB |
testcase_23 | AC | 151 ms
77,892 KB |
testcase_24 | AC | 152 ms
77,824 KB |
testcase_25 | AC | 150 ms
77,704 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")