結果

問題 No.205 マージして辞書順最小
ユーザー lam6er
提出日時 2025-04-15 22:29:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 535 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 81,988 KB
実行使用メモリ 76,408 KB
最終ジャッジ日時 2025-04-15 22:31:35
合計ジャッジ時間 1,955 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

class PriorityString:
    def __init__(self, s):
        self.s = s
    def __lt__(self, other):
        return (self.s + other.s) < (other.s + self.s)

n = int(input())
strings = [input().strip() for _ in range(n)]

heap = []
for s in strings:
    if s:
        heapq.heappush(heap, PriorityString(s))

result = []
while heap:
    current = heapq.heappop(heap)
    result.append(current.s[0])
    remaining = current.s[1:]
    if remaining:
        heapq.heappush(heap, PriorityString(remaining))

print(''.join(result))
0