結果

問題 No.470 Inverse S+T Problem
ユーザー Navier_Boltzmann
提出日時 2023-11-10 09:53:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 867 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 78,592 KB
最終ジャッジ日時 2024-09-26 00:45:09
合計ジャッジ時間 3,807 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N = int(input())
U = [input()[:-1] for _ in range(N)]
if N > 26:
    print('Impossible')
    exit()

for i in range(1<<N):
    
    
    S = []
    T = []
    
    called = defaultdict(lambda:False)
    flg = False
    for j in range(N):
        
        u = U[j]
        
        if (i>>j)&1:
            
            s = u[:2]
            t = u[2:]
        else:
            s = u[:1]
            t = u[1:]
        
        if (called[s]|called[t]):
            
            flg = True
            break
        else:
            called[s] = True
            called[t] = True
            S.append(s)
            T.append(t)
    if flg:
        continue
    for s,t in zip(S,T):
        print(s,t)
    exit()
print('Impossible')
0