/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 3ms 844.0 KiB
#3 Accepted 3ms 812.0 KiB
#4 Runtime Error malloc(): unaligned tcache chunk detected 2ms 500.0 KiB
#5 Accepted 6ms 772.0 KiB
#6 Accepted 8ms 2.328 MiB
#7 Wrong Answer 7ms 2.652 MiB
#8 Wrong Answer 3ms 492.0 KiB
#9 Runtime Error malloc(): unaligned tcache chunk detected 2ms 580.0 KiB
#10 Wrong Answer 7ms 1.566 MiB
#11 Wrong Answer 3ms 444.0 KiB
#12 Wrong Answer 4ms 596.0 KiB
#13 Wrong Answer 5ms 784.0 KiB
#14 Wrong Answer 4ms 540.0 KiB
#15 Wrong Answer 6ms 1.676 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define Yes cout<<"Yes"<<"\n";
#define No  cout<<"No"<<"\n"; 
string concat(const string &a, const string &b) {
    return a + b;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;

    while (T--) {
        int N, K;
        cin >> N >> K;
        vector<string> arr(N);
        for (int i = 0; i < N;i++) {
            cin >> arr[i];
        }
        priority_queue<pair<string, pair<int, int>>> pq;
        for (int i = 0; i < N - 1; i++) {
            pq.push({concat(arr[i], arr[i + 1]), {i, i + 1}});
        }
        for (int i= 0; i< K; i++) {
            if (pq.empty()) break;

            auto top = pq.top();
            pq.pop();

            string new_value = top.first;
            int index1 = top.second.first;
            int index2 = top.second.second;
            arr[index1] = new_value;
            arr.erase(arr.begin() + index2);
            if (index1 > 0 && index1 < arr.size()) {
                pq.push({concat(arr[index1 - 1], arr[index1]), {index1 - 1, index1}});
            }
            if (index1 + 1 < arr.size()) {
                pq.push({concat(arr[index1], arr[index1 + 1]), {index1, index1 + 1}});
            }
        }
        string max_value;
        for (const auto &value : arr) {
            if (value > max_value) {
                max_value = value;
            }
        }

        cout << max_value << '\n';
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++17 (G++ 13.2.0)
Submit At
2024-08-16 16:26:14
Judged At
2024-10-03 13:26:55
Judged By
Score
25
Total Time
8ms
Peak Memory
2.652 MiB