/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 21ms 764.0 KiB
#3 Accepted 20ms 864.0 KiB
#4 Accepted 22ms 692.0 KiB
#5 Accepted 22ms 600.0 KiB
#6 Accepted 22ms 676.0 KiB
#7 Wrong Answer 22ms 676.0 KiB
#8 Wrong Answer 3ms 484.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define Yes cout<<"Yes"<<"\n";
#define No  cout<<"No"<<"\n"; 
using namespace std;
string concatenate(const string &a, const string &b) {
    return a + b;
}
string findMaxValue(vector<string> arr, int K) {
    while (K > 0) {
        int n = arr.size();
        int best_i = -1;
        string best_val;
        for (int i = 0; i < n - 1; i++) {
            string combined = concatenate(arr[i], arr[i + 1]);
            if (combined > best_val) {
                best_val = combined;
                best_i = i;
            }
        }
        if (best_i != -1) {
            arr[best_i] = best_val;
            arr.erase(arr.begin() + best_i + 1);
            --K;
        } else {
            break;
        }
    }
    return *max_element(all(arr));
}

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 << findMaxValue(arr, K) << nl;
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++17 (G++ 13.2.0)
Submit At
2024-08-16 16:09:15
Judged At
2024-11-11 03:15:52
Judged By
Score
30
Total Time
22ms
Peak Memory
864.0 KiB