結果

問題 No.205 マージして辞書順最小
ユーザー Mister
提出日時 2020-09-04 16:37:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 722 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 81,212 KB
最終ジャッジ日時 2025-01-14 04:32:26
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

void solve() {
    MinHeap<std::string> heap;

    int n;
    std::cin >> n;
    while (n--) {
        std::string s;
        std::cin >> s;
        s.push_back('~');
        heap.push(s);
    }

    std::string t;
    while (!heap.empty()) {
        auto s = std::move(heap.top());
        heap.pop();
        if (s.front() == '~') continue;

        t.push_back(s.front());
        s.erase(s.begin());
        heap.push(s);
    }

    std::cout << t << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0