結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー pekempeypekempey
提出日時 2018-12-22 01:02:10
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 963 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 81,980 KB
実行使用メモリ 14,928 KB
最終ジャッジ日時 2024-04-22 02:45:29
合計ジャッジ時間 3,391 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,812 KB
testcase_01 AC 37 ms
6,944 KB
testcase_02 AC 33 ms
6,944 KB
testcase_03 AC 54 ms
6,940 KB
testcase_04 AC 132 ms
7,892 KB
testcase_05 AC 80 ms
7,120 KB
testcase_06 AC 82 ms
7,120 KB
testcase_07 AC 82 ms
6,992 KB
testcase_08 AC 77 ms
7,120 KB
testcase_09 AC 315 ms
14,928 KB
testcase_10 AC 323 ms
14,928 KB
testcase_11 AC 10 ms
6,940 KB
testcase_12 AC 10 ms
6,940 KB
testcase_13 AC 45 ms
6,944 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 < 50000; ii++) {
        for (int i = 0; i + 1 < n; i++) {
            if (a[i] + a[i + 1] == a[i + 1] + a[i] && a[i] < a[i + 1]) {
                swap(a[i], a[i + 1]);
            }
        }
        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