/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 5ms 3.02 MiB
#3 Accepted 5ms 2.688 MiB
#4 Accepted 5ms 2.566 MiB
#5 Accepted 5ms 2.566 MiB
#6 Accepted 5ms 2.77 MiB
#7 Accepted 5ms 2.52 MiB
#8 Accepted 2ms 580.0 KiB
#9 Accepted 1ms 580.0 KiB
#10 Accepted 5ms 2.656 MiB
#11 Accepted 2ms 320.0 KiB
#12 Accepted 3ms 836.0 KiB
#13 Accepted 3ms 1020.0 KiB
#14 Accepted 3ms 792.0 KiB
#15 Accepted 5ms 2.609 MiB

Code

// @sagorahmedmunna

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

void test() {
  int n, k;
  cin >> n >> k;
  string a[n];
  for (auto& ai : a) {
    cin >> ai;
  }
  vector<string> s;
  for (int i = 0; i < n - k; i++) {
    string temp = "";
    for (int j = i; j <= i + k; j++) {
      temp += a[j];
    }
    s.push_back(temp);
  }
  string mx = s[0];
  for (auto& si : s) {
    if (mx.size() == si.size()) {
      mx = max(mx, si);
    } else if (mx.size() < si.size()) {
      mx = si;
    }
  }
  for (auto& ai : a) {
    if (mx.size() == ai.size()) {
      mx = max(mx, ai);
    } else if (mx.size() < ai.size()) {
      mx = ai;
    }
  }
  cout << mx << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int t = 1; 
  cin >> t;
  for (int i = 1; i <= t; i++) {
    test();
  }
  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 15:56:02
Judged At
2024-11-11 03:16:49
Judged By
Score
100
Total Time
5ms
Peak Memory
3.02 MiB