結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー comaviuscomavius
提出日時 2023-07-11 15:44:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,647 bytes
コンパイル時間 2,667 ms
コンパイル使用メモリ 222,060 KB
実行使用メモリ 55,652 KB
最終ジャッジ日時 2023-10-11 06:44:58
合計ジャッジ時間 4,749 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 114 ms
23,300 KB
testcase_08 AC 121 ms
23,352 KB
testcase_09 WA -
testcase_10 AC 271 ms
55,172 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 29 ms
4,348 KB
testcase_14 AC 333 ms
48,524 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    for (ll i = 0; i < n; i++) {
        string a;
        cin >> a;
        if (a.size() == 2){
            if (a[0] == a[1]){
                v.push_back({a.substr(0, 1), 1});
                v.push_back({a.substr(0, 1), 1});
            }
            else {
                v.push_back({a, a.size()});
            }
        }
        else {
            v.push_back({a, a.size()});
        }
    }
    set<string> ls;
    std::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 < v.size(); 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