結果
問題 |
No.775 tatyamと素数大富豪(hard)
|
ユーザー |
![]() |
提出日時 | 2018-12-22 00:44:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,024 bytes |
コンパイル時間 | 2,524 ms |
コンパイル使用メモリ | 218,248 KB |
最終ジャッジ日時 | 2025-01-06 19:47:21 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 WA * 1 |
other | AC * 9 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; int N, K; int main() { cin >> N >> K; vector< string > P(N); for(int i = 0; i < N; i++) { cin >> P[i]; } vector< int > ord(N); iota(begin(ord), end(ord), 0); sort(begin(ord), end(ord), [&](const int &a, const int &b) { return P[a] + P[b] > P[b] + P[a]; }); string concat; for(auto &p : ord) concat += P[p]; priority_queue< pair< string, vector< int > > > que; que.emplace(concat, ord); set< string > memo; memo.emplace(concat); while(que.size() && K > 0) { auto p = que.top().second; cout << que.top().first << endl; --K; que.pop(); for(int i = 0; i < ord.size(); i++) { for(int j = i - 1; j >= 0; j--) { if(P[p[i]] + P[p[j]] >= P[p[j]] + P[p[i]]) continue; swap(p[i], p[j]); string con; for(auto &q : p) con += P[q]; if(memo.count(con)) continue; memo.emplace(con); que.emplace(con, p); swap(p[i], p[j]); break; } } } }