結果

問題 No.205 マージして辞書順最小
ユーザー xuzijian629
提出日時 2018-11-03 02:34:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 684 bytes
コンパイル時間 2,571 ms
コンパイル使用メモリ 209,220 KB
最終ジャッジ日時 2025-01-06 15:30:36
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    priority_queue<deque<char>, vector<deque<char>>, greater<deque<char>>> que;
    int n;
    cin >> n;
    string ret = "";
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        s += 'z' + 1;
        deque<char> deq;
        for (char c: s) {
            deq.push_back(c);
        }
        que.push(deq);
    }

    while (que.size()) {
        auto t = que.top();
        ret += t.front();
        que.pop();
        t.pop_front();
        if (t.size() > 1) {
            que.push(t);
        }
    }
    cout << ret << endl;
}
0