結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー pekempeypekempey
提出日時 2018-12-22 00:56:34
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 787 bytes
コンパイル時間 1,214 ms
コンパイル使用メモリ 80,716 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-04-22 02:43:44
合計ジャッジ時間 3,066 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
7,892 KB
testcase_01 AC 54 ms
7,892 KB
testcase_02 AC 57 ms
8,400 KB
testcase_03 AC 73 ms
9,688 KB
testcase_04 AC 111 ms
12,440 KB
testcase_05 AC 87 ms
11,048 KB
testcase_06 AC 84 ms
11,216 KB
testcase_07 AC 85 ms
11,076 KB
testcase_08 AC 87 ms
10,900 KB
testcase_09 AC 191 ms
26,764 KB
testcase_10 AC 193 ms
26,880 KB
testcase_11 AC 22 ms
8,148 KB
testcase_12 AC 21 ms
8,532 KB
testcase_13 AC 68 ms
8,780 KB
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cstdlib>

using namespace std;

int n, K;
string a[100];

bool cmp(string x, string y) {
    if (x + y != y + x) return x + y > y + x;
    return x.size() > y.size();
}

int main() {
    cin >> n >> K;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n, cmp);
    vector<string> ans;
    for (int ii = 0; ii < 100000; ii++) {
        string s;
        for (int i = 0; i < n; i++) {
            s += a[i];
        }
        ans.push_back(s);
        next_permutation(a, a + n, cmp);
    }
    sort(ans.rbegin(), ans.rend());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    for (int i = 0; i < K; i++) {
        cout << ans[i] << endl;
    }
}

0