/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Accepted 22ms 684.0 KiB
#3 Accepted 21ms 680.0 KiB
#4 Accepted 23ms 688.0 KiB
#5 Accepted 21ms 580.0 KiB
#6 Accepted 21ms 692.0 KiB
#7 Wrong Answer 22ms 692.0 KiB
#8 Wrong Answer 3ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

string solve(int n, int k, vector<string>& arr) {
    
    vector<string> current = arr;

    for (int operations = 0; operations < k && n > 1; ++operations) {
        string max_concat = "";
        int pos = -1;

      
        for (int i = 0; i < n - 1; ++i) {
            string concat = current[i] + current[i + 1];
            if (concat > max_concat) {
                max_concat = concat;
                pos = i;
            }
        }

      
        if (pos != -1) {
            current[pos] = max_concat; 
            current.erase(current.begin() + pos + 1);
            --n; 
        }
    }

    return *max_element(current.begin(), current.end());
}

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<string> str(n);

        for (int i = 0; i < n; ++i) {
            cin >> str[i];
        }

        cout << solve(n, k, str) << endl;
    }

    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 17:44:16
Judged At
2024-11-11 03:11:04
Judged By
Score
30
Total Time
23ms
Peak Memory
692.0 KiB