/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Wrong Answer 36ms 656.0 KiB
#3 Wrong Answer 38ms 644.0 KiB
#4 Wrong Answer 37ms 668.0 KiB
#5 Wrong Answer 32ms 656.0 KiB
#6 Wrong Answer 32ms 656.0 KiB
#7 Wrong Answer 33ms 648.0 KiB
#8 Wrong Answer 5ms 584.0 KiB
#9 Wrong Answer 3ms 772.0 KiB
#10 Wrong Answer 26ms 648.0 KiB
#11 Wrong Answer 2ms 540.0 KiB
#12 Wrong Answer 7ms 576.0 KiB
#13 Wrong Answer 16ms 600.0 KiB
#14 Wrong Answer 14ms 576.0 KiB
#15 Wrong Answer 29ms 644.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-10-03 13:24:35
Judged By
Score
5
Total Time
38ms
Peak Memory
772.0 KiB