/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 4ms 580.0 KiB
#3 Accepted 4ms 772.0 KiB
#4 Runtime Error malloc(): unaligned tcache chunk detected 2ms 688.0 KiB
#5 Accepted 4ms 788.0 KiB
#6 Accepted 5ms 2.52 MiB
#7 Wrong Answer 5ms 2.902 MiB
#8 Wrong Answer 2ms 568.0 KiB
#9 Runtime Error malloc(): unaligned tcache chunk detected 2ms 572.0 KiB
#10 Wrong Answer 4ms 1.797 MiB
#11 Wrong Answer 2ms 532.0 KiB
#12 Wrong Answer 2ms 576.0 KiB
#13 Wrong Answer 3ms 1.035 MiB
#14 Wrong Answer 3ms 724.0 KiB
#15 Wrong Answer 4ms 2.105 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define Yes cout<<"Yes"<<"\n";
#define No  cout<<"No"<<"\n"; 

string concatenate(const string &a, const string &b) {
    return a + b;
}

struct compare {
    bool operator()(const pair<string, int> &a, const pair<string, int> &b) {
        return a.first < b.first;
    }
};

void run(int t) {
    int n, k;
    cin >> n >> k;
    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    priority_queue<pair<string, int>, vector<pair<string, int>>, compare> max_heap;
    for (int i = 0; i < n - 1; ++i) {
        string concat1 = concatenate(a[i], a[i + 1]);
        max_heap.push({concat1, i});
    }
    for (int i = 0; i < k; ++i) {
        if (max_heap.empty()) break;

        auto [max_concat, index] = max_heap.top();
        max_heap.pop();

        a[index] = max_concat;
        a.erase(a.begin() + index + 1);

        if (index > 0) {
            string concat1 = concatenate(a[index - 1], a[index]);
            max_heap.push({concat1, index - 1});
        }
        if (index < a.size() - 1) {
            string concat2 = concatenate(a[index], a[index + 1]);
            max_heap.push({concat2, index});
        }
    }
    cout << *max_element(all(a)) << nl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    int c = 1;
    while(t--) {
        //cout << "Case " << c++ << ": ";
        run(t);
    }
    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 15:57:17
Judged At
2024-10-03 13:29:17
Judged By
Score
25
Total Time
5ms
Peak Memory
2.902 MiB