/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 21ms 648.0 KiB
#3 Accepted 21ms 636.0 KiB
#4 Accepted 22ms 764.0 KiB
#5 Accepted 22ms 688.0 KiB
#6 Accepted 21ms 628.0 KiB
#7 Wrong Answer 22ms 680.0 KiB
#8 Wrong Answer 3ms 320.0 KiB
#9 Wrong Answer 2ms 340.0 KiB
#10 Wrong Answer 20ms 636.0 KiB
#11 Wrong Answer 2ms 320.0 KiB
#12 Wrong Answer 6ms 580.0 KiB
#13 Wrong Answer 16ms 608.0 KiB
#14 Wrong Answer 12ms 604.0 KiB
#15 Wrong Answer 18ms 640.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-10-03 13:28:26
Judged By
Score
30
Total Time
22ms
Peak Memory
764.0 KiB