/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 652.0 KiB
#3 Accepted 2ms 580.0 KiB
#4 Runtime Error malloc(): unaligned tcache chunk detected 2ms 576.0 KiB
#5 Accepted 4ms 636.0 KiB
#6 Accepted 6ms 2.637 MiB
#7 Wrong Answer 5ms 3.062 MiB
#8 Wrong Answer 2ms 576.0 KiB
#9 Runtime Error malloc(): unaligned tcache chunk detected 2ms 576.0 KiB
#10 Wrong Answer 5ms 1.812 MiB
#11 Wrong Answer 2ms 320.0 KiB
#12 Wrong Answer 3ms 584.0 KiB
#13 Wrong Answer 3ms 836.0 KiB
#14 Wrong Answer 2ms 576.0 KiB
#15 Wrong Answer 4ms 2.066 MiB

Code

#include<bits/stdc++.h>
#define ll long long
#define el '\n'
#define pb push_back
#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr);
using namespace std;


int main() {

    fast;
    ll t;
    cin>>t;

    while (t--) {
        ll n,k;
        cin>>n>>k;
        vector<string>v(n);
        
        for(ll i=0;i<n;i++) {
            cin>>v[i];
        }

        
        priority_queue<pair<string,pair<ll,ll>>>pq;
        
        for(ll i=0;i<n-1;i++) {
            pq.push({v[i]+v[i+1],{i,i+1}});
        }

        while (k--) {
            if (pq.empty()) {
                break;
                }
            
            auto[concat,indices]=pq.top();
            pq.pop();
            
            ll i =indices.first,j=indices.second;
            
            v[i] = concat;
            v.erase(v.begin()+j);
            
            n--;
            
            if(i>0) {
                pq.push({v[i-1]+v[i],{i-1,i}});
            }
            if (i <n-1) {
                pq.push({v[i]+v[i+1],{i,i+1}});
            }
        }

        cout<<*max_element(v.begin(),v.end())<<el;
    }
    
    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 16:34:28
Judged At
2024-10-03 13:26:41
Judged By
Score
25
Total Time
6ms
Peak Memory
3.062 MiB