結果
問題 |
No.775 tatyamと素数大富豪(hard)
|
ユーザー |
|
提出日時 | 2018-12-22 01:10:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,023 bytes |
コンパイル時間 | 1,146 ms |
コンパイル使用メモリ | 81,264 KB |
実行使用メモリ | 14,900 KB |
最終ジャッジ日時 | 2024-10-14 01:29:25 |
合計ジャッジ時間 | 3,969 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 < 50000; ii++) { for (int i = 0; i + 1 < n; i++) { int j = i + 1; while (j > 0 && a[j - 1] + a[j] == a[j] + a[j - 1] && a[j - 1] < a[j]) { swap(a[j - 1], a[j]); j--; } } 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; } }