結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
65,688 KB
testcase_01 AC 65 ms
65,724 KB
testcase_02 AC 92 ms
72,616 KB
testcase_03 AC 83 ms
73,212 KB
testcase_04 AC 80 ms
71,788 KB
testcase_05 AC 80 ms
72,152 KB
testcase_06 AC 65 ms
65,852 KB
testcase_07 AC 105 ms
77,728 KB
testcase_08 AC 104 ms
77,756 KB
testcase_09 AC 105 ms
77,904 KB
testcase_10 AC 97 ms
77,364 KB
testcase_11 AC 99 ms
77,376 KB
testcase_12 AC 107 ms
77,612 KB
testcase_13 AC 107 ms
77,776 KB
testcase_14 AC 65 ms
65,988 KB
testcase_15 AC 64 ms
65,728 KB
testcase_16 AC 65 ms
65,712 KB
testcase_17 AC 65 ms
65,748 KB
testcase_18 AC 66 ms
65,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://yukicoder.me/problems/no/205


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


def minLexMerge(words: List[str]) -> str:
    """字典序最小的合并字符串"""
    pq = [w + chr(130) 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