結果
| 問題 |
No.775 tatyamと素数大富豪(hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-22 17:00:10 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,722 bytes |
| コンパイル時間 | 1,931 ms |
| コンパイル使用メモリ | 131,896 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-11-30 13:14:54 |
| 合計ジャッジ時間 | 11,961 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 6 WA * 1 TLE * 3 |
ソースコード
#include <algorithm>
#include <vector>
#include <iostream>
#include <numeric>
using ll = long long;
int main()
{
int N, K;
std::cin >> N >> K;
std::vector<std::string> a(N);
for (int i = 0; i < N; i++) { std::cin >> a[i]; }
auto comp = [](const std::string& s1, const std::string& s2) { return s1 + s2 == s2 + s1 ? s1.size() > s2.size() : s1 + s2 > s2 + s1; };
std::sort(a.begin(), a.end(), comp);
std::vector<int> ind(N);
std::iota(ind.begin(), ind.end(), 0);
auto next = [&]() -> bool {
std::string now;
for (int i = 0; i < N; i++) { now += a[ind[i]]; }
std::string max;
std::vector<int> maxind;
for (int i = N - 2; i >= 0; i--) {
if (ind[i] >= ind[i + 1]) { continue; }
for (int j = N - 1; j > i; j--) {
if (ind[j] <= ind[i]) { continue; }
std::swap(ind[i], ind[j]);
std::reverse(ind.begin() + i + 1, ind.end());
for (int j = i + 1; j < N; j++) {
std::swap(ind[i + 1], ind[j]);
std::string s;
for (int i = 0; i < N; i++) { s += a[ind[i]]; }
if (s < now and max < s) { max = s, maxind = ind; }
std::swap(ind[i + 1], ind[j]);
}
std::reverse(ind.begin() + i + 1, ind.end());
std::swap(ind[i], ind[j]);
// break;
}
// break;
}
return ind = maxind, (max != "");
};
for (int i = 0; i < K; i++) {
for (int i = 0; i < N; i++) { std::cout << a[ind[i]]; }
std::cout << std::endl;
if (not next()) { break; }
}
return 0;
}