/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 18ms 660.0 KiB
#3 Accepted 18ms 648.0 KiB
#4 Accepted 18ms 600.0 KiB
#5 Accepted 19ms 584.0 KiB
#6 Accepted 18ms 656.0 KiB
#7 Wrong Answer 19ms 764.0 KiB
#8 Wrong Answer 3ms 320.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-11-11 03:11:23
Judged By
Score
30
Total Time
19ms
Peak Memory
764.0 KiB