結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー pekempeypekempey
提出日時 2018-12-22 00:57:31
言語 C++11
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 787 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 80,312 KB
実行使用メモリ 120,404 KB
最終ジャッジ日時 2024-10-14 01:27:37
合計ジャッジ時間 9,856 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 9 RE * 1
権限があれば一括ダウンロードができます

ソースコード

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