結果
問題 | No.775 tatyamと素数大富豪(hard) |
ユーザー | comavius |
提出日時 | 2023-07-11 15:15:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,358 bytes |
コンパイル時間 | 2,451 ms |
コンパイル使用メモリ | 214,972 KB |
実行使用メモリ | 238,296 KB |
最終ジャッジ日時 | 2023-10-11 06:20:16 |
合計ジャッジ時間 | 11,701 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
37,124 KB |
testcase_01 | AC | 189 ms
36,208 KB |
testcase_02 | AC | 201 ms
35,836 KB |
testcase_03 | AC | 301 ms
65,472 KB |
testcase_04 | AC | 634 ms
96,776 KB |
testcase_05 | AC | 405 ms
81,928 KB |
testcase_06 | AC | 415 ms
81,300 KB |
testcase_07 | AC | 427 ms
81,228 KB |
testcase_08 | AC | 413 ms
81,120 KB |
testcase_09 | AC | 1,294 ms
238,296 KB |
testcase_10 | AC | 1,329 ms
238,076 KB |
testcase_11 | AC | 64 ms
37,160 KB |
testcase_12 | AC | 63 ms
36,240 KB |
testcase_13 | AC | 324 ms
36,536 KB |
testcase_14 | TLE | - |
ソースコード
#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(); } sort(v.begin(), v.end(), adhoc_comparator); priority_queue<string> pq; for (ll i = 0; i < 1000000; i++) { string s; for (ll j = 0; j < n; j++) { s += v[j].first; } pq.push(s); next_permutation(v.begin(), v.end(), adhoc_comparator); } string now = "z"; for (ll i = 0; i < k; i++){ while (now <= pq.top()){ pq.pop(); } cout << pq.top() << "\n"; now = pq.top(); pq.pop(); } cout << flush; }