結果
| 問題 |
No.775 tatyamと素数大富豪(hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-11 14:44:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,465 bytes |
| コンパイル時間 | 2,503 ms |
| コンパイル使用メモリ | 211,084 KB |
| 最終ジャッジ日時 | 2025-02-15 09:45:35 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 8 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const 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;
}
return false;
}
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();
}
priority_queue<string> pq;
sort(v.begin(), v.end(), adhoc_comparator);
string str;
for (auto &i : v) {
str += i.first;
}
bool flag = true;
for (ll i = 0; i < 10000; i++){
str = "";
for (ll j = 0; j < n; j++) {
str += v[j].first;
}
if (flag){
pq.push(str);
//cout << str << "\n";
flag = next_permutation(v.begin(), v.end(), adhoc_comparator);
}
}
for (ll i = 0; i < k; i++) {
str = pq.top();
pq.pop();
cout << str << "\n";
}
cout << flush;
}