/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 26ms 616.0 KiB
#3 Accepted 26ms 656.0 KiB
#4 Accepted 27ms 684.0 KiB
#5 Accepted 26ms 660.0 KiB
#6 Accepted 26ms 664.0 KiB
#7 Wrong Answer 27ms 580.0 KiB
#8 Wrong Answer 4ms 584.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define Yes cout<<"Yes"<<"\n";
#define No  cout<<"No"<<"\n"; 
string concatenate(string a, string b) {
    return a + b;
}
void run(int t){
    int  n,k,m;
    cin >> n >> k;
    vector<string> a(n);
    for(int i = 0;i<n;i++){
        cin >> a[i];
    }
     while (k > 0 && a.size() > 1) {
        int max_idx = 0;
        string max_concat = concatenate(a[0], a[1]);
        for (int i = 1; i < a.size() - 1; i++) {
            string concat = concatenate(a[i], a[i+1]);
            if (concat > max_concat) {
                max_concat = concat;
                max_idx = i;
            }
        }
        a[max_idx] = max_concat;
        a.erase(a.begin() + max_idx + 1);
        k--;
    }
    string ans = a[0];
    for (int i = 1; i < a.size(); ++i) {
        if (a[i] > ans) {
           ans= a[i];
        }
    }
    cout << ans << nl;
}
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin >> t;
    int c  = 1;
    while(t--){
        //cout << "Case " << c++ << ": ";
        run(t);
    }
    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 15:52:53
Judged At
2024-11-11 03:17:02
Judged By
Score
30
Total Time
27ms
Peak Memory
684.0 KiB