結果
問題 | No.483 マッチ並べ |
ユーザー | 👑 rin204 |
提出日時 | 2022-11-08 17:34:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 2,604 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 68,776 KB |
最終ジャッジ日時 | 2024-07-22 01:46:20 |
合計ジャッジ時間 | 4,410 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,324 KB |
testcase_01 | AC | 36 ms
53,608 KB |
testcase_02 | AC | 36 ms
53,096 KB |
testcase_03 | AC | 35 ms
53,340 KB |
testcase_04 | AC | 37 ms
52,888 KB |
testcase_05 | AC | 36 ms
53,352 KB |
testcase_06 | AC | 37 ms
53,120 KB |
testcase_07 | AC | 37 ms
53,564 KB |
testcase_08 | AC | 37 ms
53,704 KB |
testcase_09 | AC | 38 ms
54,088 KB |
testcase_10 | AC | 38 ms
53,204 KB |
testcase_11 | AC | 38 ms
53,816 KB |
testcase_12 | AC | 37 ms
53,416 KB |
testcase_13 | AC | 37 ms
53,216 KB |
testcase_14 | AC | 38 ms
53,344 KB |
testcase_15 | AC | 38 ms
54,628 KB |
testcase_16 | AC | 39 ms
53,572 KB |
testcase_17 | AC | 38 ms
53,632 KB |
testcase_18 | AC | 38 ms
53,204 KB |
testcase_19 | AC | 37 ms
53,940 KB |
testcase_20 | AC | 37 ms
53,792 KB |
testcase_21 | AC | 37 ms
54,076 KB |
testcase_22 | AC | 38 ms
53,688 KB |
testcase_23 | AC | 36 ms
53,576 KB |
testcase_24 | AC | 37 ms
53,480 KB |
testcase_25 | AC | 37 ms
53,728 KB |
testcase_26 | AC | 46 ms
62,712 KB |
testcase_27 | AC | 56 ms
68,084 KB |
testcase_28 | AC | 54 ms
68,776 KB |
testcase_29 | AC | 48 ms
64,744 KB |
testcase_30 | AC | 46 ms
63,452 KB |
testcase_31 | AC | 55 ms
68,044 KB |
testcase_32 | AC | 56 ms
67,972 KB |
testcase_33 | AC | 43 ms
60,464 KB |
testcase_34 | AC | 42 ms
61,884 KB |
testcase_35 | AC | 43 ms
61,448 KB |
testcase_36 | AC | 44 ms
60,652 KB |
testcase_37 | AC | 45 ms
63,436 KB |
testcase_38 | AC | 49 ms
64,676 KB |
testcase_39 | AC | 48 ms
63,652 KB |
testcase_40 | AC | 50 ms
65,540 KB |
testcase_41 | AC | 51 ms
65,104 KB |
testcase_42 | AC | 48 ms
65,348 KB |
testcase_43 | AC | 55 ms
67,356 KB |
testcase_44 | AC | 38 ms
54,152 KB |
testcase_45 | AC | 39 ms
53,576 KB |
testcase_46 | AC | 38 ms
53,544 KB |
testcase_47 | AC | 46 ms
63,996 KB |
testcase_48 | AC | 48 ms
65,652 KB |
testcase_49 | AC | 45 ms
63,116 KB |
testcase_50 | AC | 48 ms
65,288 KB |
testcase_51 | AC | 46 ms
64,180 KB |
testcase_52 | AC | 52 ms
66,124 KB |
testcase_53 | AC | 39 ms
54,336 KB |
testcase_54 | AC | 39 ms
54,152 KB |
testcase_55 | AC | 37 ms
54,864 KB |
ソースコード
def scc(N, G): order = [] used = [False]*N group = [None]*N RG = [[] for _ in range(N)] for i in range(N): for j in G[i]: RG[j].append(i) def dfs(pos): stack = [(1, pos), (0, pos)] while stack: t, pos = stack.pop() if t == 0: if used[pos]: stack.pop() continue used[pos] = True for npos in G[pos]: if not used[npos]: stack.append((1, npos)) stack.append((0, npos)) else: order.append(pos) def rdfs(pos, col): stack = [pos] group[pos] = col used[pos] = True while stack: pos = stack.pop() for npos in RG[pos]: if not used[npos]: used[npos] = True group[npos] = col stack.append(npos) for i in range(N): if not used[i]: dfs(i) used = [False]*N label = 0 for s in reversed(order): if not used[s]: rdfs(s, label) label += 1 return label, group class Two_SAT: def __init__(self, n): self.n = n self.G = [[] for _ in range(2 * n)] # a V B # pos_i = True -> a = i # pos_i = False -> a = ¬i def add_edge(self, i, pos_i, j, pos_j): i0 = i i1 = i + self.n if not pos_i: i0, i1 = i1, i0 j0 = j j1 = j + self.n if not pos_j: j0, j1 = j1, j0 self.G[i1].append(j0) self.G[j1].append(i0) def const(self): _, self.group = scc(2 * self.n, self.G) def check(self): for i in range(self.n): if self.group[i] == self.group[i + self.n]: return False return True def assign(self): ret = [False] * self.n for i in range(self.n): if self.group[i] > self.group[i + self.n]: ret[i] = True return ret n = int(input()) RC = [list(map(int, input().split())) for _ in range(n)] TS = Two_SAT(n) for i in range(n): r0, c0, r1, c1 = RC[i] for j in range(i + 1, n): r2, c2, r3, c3 = RC[j] for ii, p0 in enumerate([(r0, c0), (r1, c1)]): for jj, p1 in enumerate([(r2, c2), (r3, c3)]): if p0 == p1: TS.add_edge(i, ii, j, jj) TS.const() if TS.check(): print("YES") else: print("NO")