/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 436.0 KiB
#2 Accepted 2ms 788.0 KiB
#3 Accepted 2ms 788.0 KiB
#4 Runtime Error malloc(): unaligned tcache chunk detected 2ms 580.0 KiB
#5 Accepted 4ms 788.0 KiB
#6 Accepted 5ms 2.312 MiB
#7 Wrong Answer 5ms 2.566 MiB
#8 Wrong Answer 2ms 576.0 KiB
#9 Runtime Error malloc(): unaligned tcache chunk detected 2ms 744.0 KiB
#10 Wrong Answer 5ms 1.711 MiB
#11 Wrong Answer 2ms 324.0 KiB
#12 Wrong Answer 3ms 576.0 KiB
#13 Wrong Answer 3ms 832.0 KiB
#14 Wrong Answer 2ms 532.0 KiB
#15 Wrong Answer 4ms 1.812 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++){
        string concat=arr[i]+arr[i+1];
        pq.push({concat,i});
    }

    
    for (int i=0; i<k && !pq.empty(); i++) {
        auto top=pq.top();
        pq.pop();

        string max_con = top.first;
        int pos = top.second;

        arr[pos] = max_con;
        arr.erase(arr.begin()+pos+1);

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

    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:03:13
Judged At
2024-10-03 13:24:28
Judged By
Score
25
Total Time
5ms
Peak Memory
2.566 MiB