結果
| 問題 | No.2715 Unique Chimatagram | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-04-05 21:53:44 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 869 bytes | 
| コンパイル時間 | 162 ms | 
| コンパイル使用メモリ | 82,520 KB | 
| 実行使用メモリ | 83,776 KB | 
| 最終ジャッジ日時 | 2024-10-01 02:09:02 | 
| 合計ジャッジ時間 | 11,849 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 38 TLE * 2 | 
ソースコード
n = int(input())
ss = [list(input()) for _ in range(n)]
def is_timataguramu(s, t):
    kind = 0
    cnt = 0
    for i in range(26):
        if s[i] > t[i]:
            return False
        if s[i] == t[i]:
            continue
        kind += 1
        cnt += t[i] - s[i]
    return kind == 1 and cnt == 1
cnts = [[0] * 26 for _ in range(n)]
for i in range(n):
    for si in ss[i]:
        cnts[i][ord(si) - ord("a")] += 1
for i in range(n):
    for j in range(26):
        cnts[i][j] += 1
        ok = True
        for k in range(n):
            if i == k:
                continue
            if is_timataguramu(cnts[k], cnts[i]):
                ok = False
        if ok:
            ans = ""
            for l in range(26):
                ans += chr(l + ord("a")) * cnts[i][l]
            print(ans)
            exit()
        cnts[i][j] -= 1
print(-1)
            
            
            
        