/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 32ms 692.0 KiB
#3 Accepted 31ms 692.0 KiB
#4 Wrong Answer 30ms 700.0 KiB
#5 Accepted 31ms 668.0 KiB
#6 Accepted 29ms 676.0 KiB
#7 Wrong Answer 31ms 672.0 KiB
#8 Wrong Answer 5ms 540.0 KiB
#9 Wrong Answer 3ms 540.0 KiB
#10 Wrong Answer 28ms 668.0 KiB
#11 Wrong Answer 2ms 332.0 KiB
#12 Wrong Answer 6ms 600.0 KiB
#13 Wrong Answer 15ms 604.0 KiB
#14 Wrong Answer 13ms 600.0 KiB
#15 Wrong Answer 25ms 672.0 KiB

Code

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define endl '\n'
#define int long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

void solve() {
    int n, k;
    cin >> n >> k;
    vector<string> arr(n);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    string ans="";

    while(k > 0 && arr.size() > 1) {
        string max_concat = "";
        int max_index = 0;

        for(int j = 0; j < arr.size() - 1; j++) {

            string concat1 = arr[j] + arr[j + 1];
            if(concat1 > max_concat) {
                max_concat = concat1;
                max_index = j;
            }
        }
        ans=max(ans,max_concat);

        // Perform the best concatenation
        arr[max_index] = max_concat;
        arr.erase(arr.begin() + max_index+1);
        k--;
    }

    // // Find the maximum element in the resulting array
    // string max_element_in_array = *max_element(arr.begin(), arr.end());
    // cout << max_element_in_array << endl;

    cout<<ans<<endl;
}

signed main() {
    fastio;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

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 16:14:36
Judged At
2024-10-03 13:27:59
Judged By
Score
25
Total Time
32ms
Peak Memory
700.0 KiB