/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 328.0 KiB
#2 Wrong Answer 18ms 632.0 KiB
#3 Wrong Answer 18ms 612.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;


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

int main() {
    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];
        }
        
        for (int i = 0; i < K && arr.size() > 1; i++) {
            string max_concat = "";
            int index = 0;
            for (int j = 0; j < arr.size() - 1; j++) {
                string concatenated = concatenate_max(arr[j], arr[j + 1]);
                if (concatenated > max_concat) {
                    max_concat = concatenated;
                    index = j;
                }
            }
            arr[index] = max_concat;
            arr.erase(arr.begin() + index + 1);  
        }
        
        string result = arr[0];
        for (int i = 1; i < arr.size(); i++) {
            //cout << arr[i] << " ";
            result = concatenate_max(result, arr[i]);
        }
        
        cout << arr[K] << 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:01:42
Judged At
2024-11-11 03:13:06
Judged By
Score
5
Total Time
18ms
Peak Memory
632.0 KiB