結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
20,980 KB
testcase_01 AC 295 ms
21,308 KB
testcase_02 AC 307 ms
19,820 KB
testcase_03 AC 395 ms
34,300 KB
testcase_04 AC 611 ms
50,280 KB
testcase_05 AC 457 ms
42,344 KB
testcase_06 AC 495 ms
42,376 KB
testcase_07 AC 460 ms
42,476 KB
testcase_08 AC 463 ms
42,308 KB
testcase_09 AC 1,118 ms
120,264 KB
testcase_10 AC 1,083 ms
120,464 KB
testcase_11 AC 112 ms
20,672 KB
testcase_12 AC 111 ms
20,964 KB
testcase_13 AC 354 ms
21,472 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 < 500000; 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