/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 5ms 2.969 MiB
#3 Accepted 5ms 2.691 MiB
#4 Accepted 5ms 2.566 MiB
#5 Accepted 6ms 2.629 MiB
#6 Accepted 5ms 2.77 MiB
#7 Accepted 5ms 2.566 MiB
#8 Accepted 2ms 532.0 KiB
#9 Accepted 1ms 532.0 KiB
#10 Accepted 5ms 2.711 MiB
#11 Accepted 2ms 324.0 KiB
#12 Accepted 3ms 892.0 KiB
#13 Accepted 2ms 832.0 KiB
#14 Accepted 2ms 788.0 KiB
#15 Accepted 5ms 2.566 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-11-11 03:10:32
Judged By
Score
100
Total Time
6ms
Peak Memory
2.969 MiB