結果
問題 |
No.775 tatyamと素数大富豪(hard)
|
ユーザー |
|
提出日時 | 2023-07-11 15:38:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,345 bytes |
コンパイル時間 | 2,678 ms |
コンパイル使用メモリ | 215,620 KB |
最終ジャッジ日時 | 2025-02-15 09:48:54 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 9 RE * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; bool adhoc_comparator(const pair<string, ll> &a, const pair<string, ll> &b) { ll check_len = min(a.first.size(), b.first.size()); for (ll i = 0; i < check_len; i++) { if (a.first[i] != b.first[i]) { return a.first[i] > b.first[i]; } } if (a.first.size() < b.first.size()){ return adhoc_comparator(a, {b.first.substr(check_len), b.second}); } if (a.first.size() > b.first.size()){ return adhoc_comparator({a.first.substr(check_len), a.second}, b); } else { return a.second > b.second; } } int main() { ll n, k; cin >> n >> k; vector<pair<string, ll>> v(n); for (ll i = 0; i < n; i++) { cin >> v[i].first; v[i].second = v[i].first.size(); } set<string> ls; sort(v.begin(), v.end(), adhoc_comparator); priority_queue<string> pq; for (ll i = 0; i < k * 100; i++) { string s; for (ll j = 0; j < n; j++) { s += v[j].first; } if (ls.find(s) == ls.end()) { ls.insert(s); pq.push(s); } next_permutation(v.begin(), v.end(), adhoc_comparator); } for (ll i = 0; i < k; i++){ cout << pq.top() << "\n"; pq.pop(); } cout << flush; }