/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 26ms 664.0 KiB
#3 Accepted 26ms 664.0 KiB
#4 Accepted 27ms 692.0 KiB
#5 Accepted 26ms 660.0 KiB
#6 Accepted 26ms 660.0 KiB
#7 Wrong Answer 26ms 680.0 KiB
#8 Wrong Answer 4ms 764.0 KiB
#9 Wrong Answer 2ms 532.0 KiB
#10 Wrong Answer 24ms 632.0 KiB
#11 Wrong Answer 2ms 532.0 KiB
#12 Wrong Answer 7ms 580.0 KiB
#13 Wrong Answer 21ms 592.0 KiB
#14 Wrong Answer 15ms 588.0 KiB
#15 Wrong Answer 23ms 672.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-10-03 13:29:37
Judged By
Score
30
Total Time
27ms
Peak Memory
764.0 KiB