結果

問題 No.205 マージして辞書順最小
ユーザー mamekin
提出日時 2015-07-22 21:14:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,405 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 106,892 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-08 11:54:26
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

vector<string> s;

bool getNext(int k, int i, tuple<char, char, int, char, int, int>& x)
{
    int n = s[k].size();
    if(i == n)
        return false;

    int j = i;
    int len = 0;
    while(j < n && s[k][j] == s[k][i]){
        ++ j;
        ++ len;
    }

    if(j == n)
        x = make_tuple(s[k][i], '~', len, '~', k, j);
    else
        x = make_tuple(s[k][i], max(s[k][i], s[k][j]), len, s[k][j], k, j);

    return true;
}

int main()
{
    int n;
    cin >> n;
    s.resize(n);
    for(int i=0; i<n; ++i)
        cin >> s[i];

    set<tuple<char, char, int, char, int, int> > select;
    for(int i=0; i<n; ++i){
        tuple<char, char, int, char, int, int> x;
        getNext(i, 0, x);
        select.insert(x);
    }

    string ans;
    while(!select.empty()){
        auto x = *select.begin();
        select.erase(select.begin());

        ans += string(get<2>(x), get<0>(x));
        if(getNext(get<4>(x), get<5>(x), x))
            select.insert(x);
    }
    cout << ans << endl;

    return 0;
}
0