結果
問題 | No.470 Inverse S+T Problem |
ユーザー | timi |
提出日時 | 2023-11-25 17:29:13 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,384 bytes |
コンパイル時間 | 348 ms |
コンパイル使用メモリ | 81,768 KB |
実行使用メモリ | 67,976 KB |
最終ジャッジ日時 | 2024-09-26 11:01:02 |
合計ジャッジ時間 | 3,942 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
ソースコード
from collections import deque import sys sys.setrecursionlimit(10**7) N=int(input()) AA=[];A=[] for _ in range(N): S=input() AA.apend(S) AA=sorted(AA) for S in AA: a,b,c,d=S[:1],S[1:],S[:2],S[2:] A.append((a,b,c,d)) 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 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): 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 G=[[] for i in range(2*N)]; RG=[[] for i in range(2*N)] for i in range(N-1): for j in range(i+1,N): a,b,c,d=A[i];aa,bb,cc,dd=A[j] e=0 D=[a,b,aa,bb] if len(D)!=len(set(D)): add_edge(i,0,j,0) e+=1 D=[a,b,cc,dd] if len(D)!=len(set(D)): add_edge(i,0,j,1) e+=1 D=[c,d,aa,bb] if len(D)!=len(set(D)): add_edge(i,1,j,0) e+=1 D=[c,d,cc,dd] if len(D)!=len(set(D)): add_edge(i,1,j,1) e+=1 if e==4: print('Impossible') exit() B=scc(2*N, G, RG) for i in range(N): if B[i]==B[i+N]: print('Impossible') exit() for i in range(N): if B[i]<B[i+N]: print(A[i][0],A[i][1]) else: print(A[i][2],A[i][3])