/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 21ms 684.0 KiB
#3 Accepted 21ms 672.0 KiB
#4 Accepted 22ms 580.0 KiB
#5 Accepted 21ms 604.0 KiB
#6 Accepted 21ms 672.0 KiB
#7 Wrong Answer 22ms 580.0 KiB
#8 Wrong Answer 4ms 580.0 KiB
#9 Wrong Answer 2ms 320.0 KiB
#10 Wrong Answer 19ms 580.0 KiB
#11 Wrong Answer 2ms 532.0 KiB
#12 Wrong Answer 6ms 532.0 KiB
#13 Wrong Answer 16ms 620.0 KiB
#14 Wrong Answer 12ms 600.0 KiB
#15 Wrong Answer 18ms 628.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-10-03 13:21:04
Judged By
Score
30
Total Time
22ms
Peak Memory
684.0 KiB