/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 544.0 KiB
#2 Accepted 22ms 660.0 KiB
#3 Accepted 21ms 664.0 KiB
#4 Accepted 21ms 696.0 KiB
#5 Accepted 21ms 676.0 KiB
#6 Accepted 21ms 664.0 KiB
#7 Wrong Answer 22ms 628.0 KiB
#8 Wrong Answer 3ms 580.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)

string concatenate(string a, string b) {
    return a + b;
}

void solve() {
    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; i++) {
        int max_index = -1;
        string max_concat = "";
        
        for(int j = 0; j < arr.size() - 1; j++) {
            string concat1 = concatenate(arr[j], arr[j + 1]);
            if (concat1 > max_concat) {
                max_concat = concat1;
                max_index = j;
            }
        }
        
        if (max_index == -1) break; 

        arr[max_index] = max_concat;
        arr.erase(arr.begin() + max_index + 1);
    }
    string max_element_in_array = *max_element(arr.begin(), arr.end());
    cout << max_element_in_array << 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:04:34
Judged At
2024-11-11 03:16:12
Judged By
Score
30
Total Time
22ms
Peak Memory
696.0 KiB