結果

問題 No.205 マージして辞書順最小
ユーザー mamekinmamekin
提出日時 2015-07-22 21:14:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,405 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 106,012 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-22 21:20:00
合計ジャッジ時間 1,651 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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