/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 18ms 576.0 KiB
#3 Accepted 18ms 652.0 KiB
#4 Accepted 17ms 664.0 KiB
#5 Accepted 18ms 640.0 KiB
#6 Accepted 18ms 640.0 KiB
#7 Wrong Answer 19ms 644.0 KiB
#8 Wrong Answer 3ms 532.0 KiB
#9 Wrong Answer 2ms 532.0 KiB
#10 Wrong Answer 17ms 644.0 KiB
#11 Wrong Answer 2ms 532.0 KiB
#12 Wrong Answer 5ms 580.0 KiB
#13 Wrong Answer 13ms 576.0 KiB
#14 Wrong Answer 10ms 576.0 KiB
#15 Wrong Answer 16ms 656.0 KiB

Code

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

string solve(vector<string>& arr, int K) {
    while (K-- > 0 && arr.size() > 1) {
        int idx = -1;
        string maxConcat = "";
        for (int i = 0; i < arr.size() - 1; i++) {
            string concat = arr[i] + arr[i + 1];
            if (concat > maxConcat) {
                maxConcat = concat;
                idx = i;
            }
        }
        arr[idx] = maxConcat;
        arr.erase(arr.begin() + idx + 1);
    }
    return *max_element(arr.begin(), arr.end());
}

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];
        cout << solve(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:33:06
Judged At
2024-10-03 13:21:34
Judged By
Score
30
Total Time
19ms
Peak Memory
664.0 KiB