結果

問題 No.205 マージして辞書順最小
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-03-27 01:17:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 520 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 81,548 KB
実行使用メモリ 77,944 KB
最終ジャッジ日時 2023-10-19 13:57:21
合計ジャッジ時間 2,497 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
67,736 KB
testcase_01 AC 67 ms
67,736 KB
testcase_02 AC 80 ms
72,740 KB
testcase_03 AC 83 ms
73,344 KB
testcase_04 AC 79 ms
72,532 KB
testcase_05 AC 80 ms
72,540 KB
testcase_06 AC 65 ms
67,756 KB
testcase_07 AC 105 ms
77,772 KB
testcase_08 AC 105 ms
77,812 KB
testcase_09 AC 105 ms
77,944 KB
testcase_10 AC 97 ms
77,464 KB
testcase_11 AC 100 ms
77,472 KB
testcase_12 AC 109 ms
77,664 KB
testcase_13 AC 109 ms
77,816 KB
testcase_14 AC 67 ms
67,756 KB
testcase_15 AC 65 ms
67,756 KB
testcase_16 AC 66 ms
67,756 KB
testcase_17 AC 64 ms
67,756 KB
testcase_18 AC 65 ms
67,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
from typing import List


def minLexMerge(words: List[str]) -> str:
    """字典序最小的合并字符串"""
    pq = [w + chr(200) for w in words]
    heapify(pq)
    res = []
    while pq:
        min_ = heappop(pq)
        res.append(min_[0])
        min_ = min_[1:]
        if len(min_) >= 2:
            heappush(pq, min_)
    return "".join(res)


if __name__ == "__main__":
    N = int(input())
    words = [input() for _ in range(N)]
    print(minLexMerge(words))
0