/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 392.0 KiB
#2 Accepted 3ms 1020.0 KiB
#3 Accepted 2ms 832.0 KiB
#4 Runtime Error 2ms 580.0 KiB
#5 Accepted 4ms 580.0 KiB
#6 Accepted 5ms 2.312 MiB
#7 Wrong Answer 5ms 2.562 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-11-11 03:14:45
Judged By
Score
25
Total Time
5ms
Peak Memory
2.562 MiB