結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
7,376 KB
testcase_01 AC 63 ms
7,884 KB
testcase_02 AC 68 ms
8,532 KB
testcase_03 AC 109 ms
10,068 KB
testcase_04 AC 259 ms
12,540 KB
testcase_05 AC 158 ms
10,996 KB
testcase_06 AC 159 ms
11,092 KB
testcase_07 AC 152 ms
11,092 KB
testcase_08 AC 157 ms
11,016 KB
testcase_09 AC 633 ms
26,596 KB
testcase_10 AC 633 ms
26,928 KB
testcase_11 AC 20 ms
7,632 KB
testcase_12 AC 20 ms
7,888 KB
testcase_13 AC 86 ms
8,524 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++) {
        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