結果

問題 No.205 マージして辞書順最小
ユーザー hk0209hk0209
提出日時 2021-02-18 18:20:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 167,868 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 02:09:00
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPE(i,l,n) for(ll i=l;i<=ll(n);i++)
#define FORA(i,I) for(const auto& i:I)
int main(){
    bool f = true;
    ll n, index = -1;
    string t = "";
    char now = '~';
    cin >> n;
    vector<string> v(n);
    REP(i, n){
        cin >> v[i];
        v[i] += "~";//番兵
    }
    while(f){
        f = false;
        now = '~';
        index = -1;

        REP(i, n){    
            if(v[i] != "~"){
                f = true;
                if(now > v[i][0]){
                    now = v[i][0];
                    index = i;
                } else if (now == v[i][0]){
                    if(v[index] > v[i]) index = i;
                }
            }
        }
        if(index >= 0){
            t += now;
            v[index].erase(0, 1);
        }
    }
    cout << t << endl;
}
0