Submission #3772180


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<string> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  vector<bitset<10001>> bs(n + 1);
  bs[n].set(k);
  vector<vector<pair<int, int>>> v(2);
  for (int i = n - 1; i >= 0; --i) {
    int sz = (int) s[i].size();
    bs[i] = bs[i + 1] | (bs[i + 1] >> sz);
    if (bs[i + 1][sz]) {
      v[0].emplace_back(i, 0);
    }
  }
  string ans = "";
  for (int i = 0; i < k; ++i) {
    int iter = i & 1;
    char c = 'z';
    for (const auto& p : v[iter]) {
      c = min(c, s[p.first][p.second]);
    }
    ans += c;
    int bid = n;
    for (const auto& p : v[iter]) {
      int id, j;
      tie(id, j) = p;
      if (s[id][j] != c) {
        continue;
      }
      if (j == (int) s[id].size() - 1) {
        bid = min(bid, id);
      } else {
        v[iter ^ 1].emplace_back(id, j + 1);
      }
    }
    for (int j = bid + 1; j < n; ++j) {
      if (i + 1 + (int) s[j].size() <= k && bs[j + 1][i + 1 + (int) s[j].size()]) {
        v[iter ^ 1].emplace_back(j, 0);
      }
    }
    v[iter].clear();
  }
  cout << ans << '\n';
  return 0;
}

Submission Info

Submission Time
Task F - Iroha Loves Strings
User nthoang
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1246 Byte
Status TLE
Exec Time 5256 ms
Memory 13548 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1500
Status
AC × 3
AC × 25
TLE × 4
Set Name Test Cases
Sample 0_sample01, 0_sample02, 0_sample03
All 0_sample01, 0_sample02, 0_sample03, abab0, abten0, allsame0, allsame_ex0, bigrand0, bigrand1, firstlast0, firstlast1, fullrand0, fullrand1, fullrand2, kaidan0, maxrand0, maxrand1, maxrand2, roll_hyper0, roll_hyper1, roll_hyper_r0, rolling0, rolling1, smallc0, smallc1, smallrand0, smallrand1, smallrand2, zzza0
Case Name Status Exec Time Memory
0_sample01 AC 1 ms 256 KB
0_sample02 AC 1 ms 256 KB
0_sample03 AC 1 ms 256 KB
abab0 TLE 5256 ms 4588 KB
abten0 AC 5 ms 3328 KB
allsame0 TLE 5256 ms 12928 KB
allsame_ex0 TLE 5256 ms 7012 KB
bigrand0 AC 4 ms 2304 KB
bigrand1 AC 4 ms 2944 KB
firstlast0 AC 5 ms 3328 KB
firstlast1 AC 5 ms 3328 KB
fullrand0 AC 5 ms 3328 KB
fullrand1 AC 5 ms 3328 KB
fullrand2 AC 5 ms 3328 KB
kaidan0 TLE 5256 ms 13548 KB
maxrand0 AC 4 ms 3200 KB
maxrand1 AC 4 ms 3200 KB
maxrand2 AC 5 ms 3200 KB
roll_hyper0 AC 6 ms 3840 KB
roll_hyper1 AC 6 ms 3840 KB
roll_hyper_r0 AC 6 ms 3840 KB
rolling0 AC 6 ms 3840 KB
rolling1 AC 6 ms 3840 KB
smallc0 AC 342 ms 3712 KB
smallc1 AC 356 ms 3712 KB
smallrand0 AC 1 ms 256 KB
smallrand1 AC 1 ms 256 KB
smallrand2 AC 1 ms 256 KB
zzza0 AC 6 ms 2688 KB