/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 6ms 620.0 KiB
#3 Accepted 5ms 584.0 KiB
#4 Accepted 3ms 576.0 KiB
#5 Accepted 3ms 576.0 KiB
#6 Accepted 3ms 504.0 KiB
#7 Accepted 3ms 580.0 KiB
#8 Accepted 2ms 576.0 KiB
#9 Accepted 2ms 324.0 KiB
#10 Accepted 3ms 580.0 KiB
#11 Accepted 1ms 320.0 KiB
#12 Accepted 2ms 532.0 KiB
#13 Accepted 2ms 576.0 KiB
#14 Accepted 2ms 576.0 KiB
#15 Accepted 3ms 476.0 KiB

Code

/**
 *  written by Binoy Barman .
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define int long long

bool check(string &a, string &b) {
    if(a.length() < b.length()) return true;
    if(a.length() > b.length()) return false;
    for (int i = 0; i < a.length(); i++) {
        if(a[i] < b[i]) return true;
        else if(a[i] > b[i]) return false;
    }
    return false;
}

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Too_Many_Jobs {
        int n, k;
        cin >> n >> k;
        vector<string> a(n);
        string mx = "";
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if(i <= k) {
                for(auto c : a[i]) mx.push_back(c);
            }
        }
        string pre = mx;
        for (int i = 1; i < n; i++) {
            if(i + k >= n) break;
            string cur = pre;
            reverse(all(cur));
            for (int j = 0; j < a[i - 1].length(); j++) {
                cur.pop_back();
            }
            reverse(all(cur));
            for(auto c : a[i + k]) cur.push_back(c);
            pre = cur;
            if(check(mx, cur)) swap(mx, cur);
        }
        cout << mx << nl;
    }

    return 0;
}

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:03:21
Judged At
2024-11-11 03:16:17
Judged By
Score
100
Total Time
6ms
Peak Memory
620.0 KiB