/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 3ms 584.0 KiB
#3 Accepted 3ms 584.0 KiB
#4 Runtime Error 3ms 692.0 KiB
#5 Accepted 7ms 780.0 KiB
#6 Accepted 8ms 2.605 MiB
#7 Wrong Answer 8ms 3.023 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-11-11 03:14:34
Judged By
Score
25
Total Time
8ms
Peak Memory
3.023 MiB