結果

問題 No.2715 Unique Chimatagram
ユーザー akasia_midoriakasia_midori
提出日時 2024-04-05 23:13:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,936 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 86,208 KB
最終ジャッジ日時 2024-04-05 23:13:56
合計ジャッジ時間 4,359 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
62,408 KB
testcase_01 AC 42 ms
55,604 KB
testcase_02 AC 46 ms
61,144 KB
testcase_03 AC 42 ms
55,604 KB
testcase_04 AC 42 ms
55,604 KB
testcase_05 AC 42 ms
55,604 KB
testcase_06 AC 44 ms
55,604 KB
testcase_07 AC 41 ms
55,604 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def oi(): return int(input())
def os(): return input().rstrip()
def mi(): return list(map(int, input().split()))

# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import defaultdict, Counter
input_count = 0

N = oi()
dicts = defaultdict(int)
out = []
for _ in range(N):
    S = "".join(sorted(list(os())))
    dicts[S] += 1
# 包含関係を確認する
OK = []

# Aの中にBが含まれていたらTrueを返す
def check(A, B):
    As = Counter(A)
    Bs = Counter(B)

    keys = set(list(As.keys()) + list(Bs.keys()))
    
    if len(A) < len(B):
        for k in keys:
            if k not in Bs and k in As:
                return False

            if k in As and k in Bs and As[k] > Bs[k]:
                return False

    elif len(A) > len(B):
        for k in keys:
            if k in Bs and k not in As:
                return False

            if k in As and k in Bs and As[k] < Bs[k]:
                return False
    else:
        if set(list(As.keys())) != set(list(Bs.keys())):
            return False
        
        for k in keys:
            if As[k] != Bs[k]:
                return False
            
    return True
OK_list = []
keys = list(dicts.keys())
for i in range(len(keys)):
    o1 = keys[i]
    flg = True
    for j in range(i+1, len(keys)):
        o2 = keys[j]
        if check(o1, o2):
            flg = False
            break
        
    if flg:
        OK_list.append(o1)
alpha = [chr(ord("a")+i) for i in range(26)]
output = "-1"
flg = False
for o in OK_list:
    for a in alpha:
        temp = "".join(sorted(list(o+a)))
        count = 0
        for o1 in dicts.keys():
            if check(temp, o1):
                count += dicts[o1]
        
        if count == 1:
            output = temp
            flg=True
            break
    if flg:
        break
print(output)
0