結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー comaviuscomavius
提出日時 2023-07-11 15:37:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,343 bytes
コンパイル時間 2,750 ms
コンパイル使用メモリ 219,648 KB
実行使用メモリ 8,328 KB
最終ジャッジ日時 2023-10-11 06:38:32
合計ジャッジ時間 3,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 10 ms
4,872 KB
testcase_04 AC 7 ms
4,352 KB
testcase_05 AC 10 ms
5,044 KB
testcase_06 AC 11 ms
5,076 KB
testcase_07 AC 12 ms
5,140 KB
testcase_08 AC 12 ms
5,080 KB
testcase_09 AC 25 ms
8,204 KB
testcase_10 AC 26 ms
8,328 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 < 10000; 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;
}
0