結果

問題 No.205 マージして辞書順最小
ユーザー tottoripaper
提出日時 2015-05-08 23:28:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 820 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 63,988 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 20:40:09
合計ジャッジ時間 1,551 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 7 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

std::string S[50];

int main(){
    int N;
    std::cin >> N;

    int L = 0;
    for(int i=0;i<N;i++){
        std::cin >> S[i];
        L += S[i].size();
    }
    
    std::string T = "";
    std::string *first = S;
    for(int i=0;i<L;i++){
        std::sort(first, first+N, [](const std::string& lhs, const std::string& rhs){
                int l = std::min(lhs.size(), rhs.size());
                for(int i=0;i<l;i++){
                    if(lhs[i] != rhs[i]){
                        return lhs[i] < rhs[i];
                    }
                }
                return lhs.size() < rhs.size();
        });

        T += (*first)[0];
        first->erase(0, 1);
        if(first->empty()){
            ++first; --N;
        }
    }

    std::cout << T << std::endl;
}
0