/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 4ms 588.0 KiB
#3 Accepted 4ms 588.0 KiB
#4 Wrong Answer 3ms 488.0 KiB
#5 Accepted 6ms 592.0 KiB
#6 Accepted 8ms 2.223 MiB
#7 Wrong Answer 7ms 2.633 MiB

Code

#include <bits/stdc++.h>
using namespace std;

string solve(int n, int k, vector<string>& arr) {

    priority_queue<pair<string, int>> pq;

    for (int i = 0; i < n - 1; ++i) {
        pq.push({arr[i] + arr[i + 1], i});
    }

    for (int op = 0; op < k && !pq.empty(); ++op) {

        auto top = pq.top();
        pq.pop();
        string max_concat = top.first;
        int pos = top.second;

        arr[pos] = max_concat;
        arr.erase(arr.begin() + pos + 1);
        --n;

        if (pos > 0) {
            pq.push({arr[pos - 1] + arr[pos], pos - 1});
        }
        if (pos < arr.size() - 1) {
            pq.push({arr[pos] + arr[pos + 1], pos});
        }
    }

    return *max_element(arr.begin(), arr.end());
}

int main() {
   
    int t;
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<string> str(n);

        for (int i = 0; i < n; ++i) {
            cin >> str[i];
        }

        cout << solve(n, k, str) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 17:35:58
Judged At
2024-11-11 03:11:15
Judged By
Score
25
Total Time
8ms
Peak Memory
2.633 MiB