結果

問題 No.205 マージして辞書順最小
ユーザー h_nosonh_noson
提出日時 2016-06-03 18:33:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,303 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 65,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 23:35:19
合計ジャッジ時間 1,368 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int sp[50];
string s[50];

bool cmp(int x, int y) {
    int i = sp[x], j = sp[y];
    while (true) {
        if (i >= s[x].size())
            return false;
        if (j >= s[y].size())
            return true;
        if (s[x][i] < s[y][j])
            return true;
        else if (s[x][i] > s[y][j])
            return false;
        i++; j++;
    }
}

int main(void) {
    int i, n;
    cin >> n;
    rep (i,n) cin >> s[i];
    rep (i,n) sp[i] = 0;
    while (true) {
        char mn = 'z'+1;
        int imn = -1;
        rep (i,n) if (sp[i] < s[i].size()) {
            if (mn > s[i][sp[i]]) {
                mn = s[i][sp[i]];
                imn = i;
            }
            else if (mn == s[i][sp[i]]) {
                if (cmp(i,imn)) {
                    mn = s[i][sp[i]];
                    imn = i;
                }
            }
        }
        if (mn == 'z'+1) break;
        cout << mn;
        sp[imn]++;
    }
    cout << endl;
    return 0;
}
0