結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー comaviuscomavius
提出日時 2023-07-11 14:45:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 2,525 ms
コンパイル使用メモリ 215,208 KB
実行使用メモリ 26,744 KB
最終ジャッジ日時 2023-10-11 05:53:04
合計ジャッジ時間 3,956 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,480 KB
testcase_01 AC 6 ms
4,348 KB
testcase_02 AC 6 ms
4,352 KB
testcase_03 AC 31 ms
10,368 KB
testcase_04 WA -
testcase_05 AC 38 ms
11,480 KB
testcase_06 AC 39 ms
11,744 KB
testcase_07 AC 42 ms
11,056 KB
testcase_08 AC 42 ms
11,468 KB
testcase_09 AC 125 ms
26,576 KB
testcase_10 AC 130 ms
26,744 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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