結果

問題 No.205 マージして辞書順最小
ユーザー 小指が強い人小指が強い人
提出日時 2016-01-11 03:40:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,201 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 58,236 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 22:44:41
合計ジャッジ時間 1,211 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int main(void)
{
    int n;
    int smax = 0;
    string s[50];
    int index[50] = {0};
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s[i];
        smax += s[i].size();     
    }
    string res = "";
    for(int i = 0; i < smax; i++) {
        int buf[50];
        int len = 0;
        for(int j = 0; j < n; j++)
            if(index[j] < s[j].size())
                buf[len++] = j;
        for(int t = 0; t < 50 && len > 1; t++) {
            int nlen = 0;
            char mini = 127;
            for(int j = 0; j < len; j++) {
                int k = buf[j];
                if(index[k] + t >= s[k].size())
                    continue;
                int p = index[k] + t;
                if(s[k][p] < mini) {
                    buf[0] = k;
                    mini = s[k][p];
                    nlen = 1;
                }
                else if(s[k][p] == mini) {
                    buf[nlen++] = k;
                }
            }
            len = nlen;
            if(mini == 127)
                break;
        }
        res += s[buf[0]][index[buf[0]]];
        index[buf[0]]++;
    }
    cout << res << endl;
    return 0;
}
0