結果
問題 |
No.205 マージして辞書順最小
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:58:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 95 ms / 5,000 ms |
コード長 | 535 bytes |
コンパイル時間 | 433 ms |
コンパイル使用メモリ | 81,776 KB |
実行使用メモリ | 76,608 KB |
最終ジャッジ日時 | 2025-04-16 16:01:00 |
合計ジャッジ時間 | 2,267 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
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))