/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 8ms 1.73 MiB
#3 Accepted 11ms 1.625 MiB
#4 Accepted 7ms 3.777 MiB
#5 Accepted 8ms 3.695 MiB
#6 Accepted 7ms 3.777 MiB
#7 Accepted 9ms 3.898 MiB
#8 Accepted 2ms 540.0 KiB
#9 Accepted 3ms 392.0 KiB
#10 Accepted 7ms 3.531 MiB
#11 Accepted 2ms 540.0 KiB
#12 Accepted 4ms 984.0 KiB
#13 Accepted 6ms 1.32 MiB
#14 Accepted 5ms 936.0 KiB
#15 Accepted 9ms 3.355 MiB

Code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
// #define cerr if(0)cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/

void Solve()
{
    ll n, k;
    cin >> n >> k;
    vector<string> arr(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    struct CustomComparator {
        bool operator()(const string& a, const string& b) const {
            // Implement your custom comparison logic here
            // Return true if a should be placed before b in the set, false otherwise
            // You can use any comparison operator or custom logic based on your requirements
            if (sz(a) != sz(b))
                return sz(a) > sz(b);
            for (int i = 0; i < sz(a); i++) {
                if (a[i] != b[i])
                    return a[i] > b[i];
            }
            return false;
        }
    };

    set<string, CustomComparator> s;
    for (int i = 0; i < n; i++) {
        string tmp = arr[i];
        ll K = k;
        for (int j = i + 1; j < n && K; j++) {
            tmp += arr[j];
            K--;
        }
        s.insert(tmp);
    }
    cout << *s.begin() << '\n';
}

int32_t main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:30:49
Judged At
2024-08-16 16:30:49
Judged By
Score
100
Total Time
11ms
Peak Memory
3.898 MiB