/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 5ms 3.02 MiB
#3 Accepted 5ms 2.77 MiB
#4 Accepted 5ms 2.77 MiB
#5 Accepted 6ms 2.762 MiB
#6 Accepted 5ms 2.77 MiB
#7 Accepted 5ms 2.52 MiB
#8 Accepted 2ms 532.0 KiB
#9 Accepted 3ms 532.0 KiB
#10 Accepted 13ms 2.52 MiB
#11 Accepted 5ms 324.0 KiB
#12 Accepted 8ms 732.0 KiB
#13 Accepted 6ms 788.0 KiB
#14 Accepted 7ms 888.0 KiB
#15 Accepted 9ms 2.52 MiB

Code

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

#define all(v) v.begin(), v.end()

using LL = long long;

int main() {
  cin.tie (nullptr) -> ios_base :: sync_with_stdio (false);

  int tests;
  cin >> tests;
  while (tests--) {
    int n, k;
    cin >> n >> k;
    vector <int> pref (n + 1);
    string text = "";
    for (int i = 1; i <= n; i++) {
      string s;
      cin >> s;
      text += s;
      pref[i] = s.size () + pref[i - 1];
    }
    vector <string> v;
    for (int i = 0; i + k + 1 <= n; i++) {
      string s = text.substr (pref[i], pref[i + k + 1] - pref[i]);
      v.push_back (s);
    }
    sort (all (v));
    sort (all (v), [&] (string a, string b) {
      if (a.size () == b.size ()) return a < b;
      return a.size () < b.size ();
    });
    // for (auto c : v) cerr << c << endl;
    cout << v.back () << '\n';
  }

  return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 19:06:28
Judged At
2024-08-16 19:06:28
Judged By
Score
100
Total Time
13ms
Peak Memory
3.02 MiB