結果
| 問題 |
No.775 tatyamと素数大富豪(hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-22 01:01:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 964 bytes |
| コンパイル時間 | 1,302 ms |
| コンパイル使用メモリ | 81,232 KB |
| 実行使用メモリ | 26,704 KB |
| 最終ジャッジ日時 | 2024-10-14 01:28:31 |
| 合計ジャッジ時間 | 5,584 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 9 RE * 1 |
ソースコード
#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;
}
}