結果

問題 No.1192 半部分列
ユーザー risujirohrisujiroh
提出日時 2020-08-22 16:24:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 887 bytes
コンパイル時間 2,541 ms
コンパイル使用メモリ 254,036 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-23 10:32:45
合計ジャッジ時間 5,968 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int n = size(s), m = size(t);
  vector<int> p(n + 1);
  p[n] = m;
  for (int i = n; i--;) {
    p[i] = p[i + 1] - 1;
    while (p[i] >= 0 and t[p[i]] != s[i]) --p[i];
  }
  if (p[0] >= 0) {
    cout << "-1\n";
    exit(0);
  }
  vector<array<int, 26>> nxt(n + 1);
  nxt[n].fill(n);
  for (int i = n; i--;) {
    nxt[i] = nxt[i + 1];
    nxt[i][s[i] - 'a'] = i;
  }
  string res;
  int i = 0, j = 0;
  while (true) {
    for (char c = 'a'; c <= 'z'; ++c) {
      if (p[nxt[i][c - 'a']] >= j) continue;
      res += c;
      i = nxt[i][c - 'a'] + 1;
      while (j < m and t[j] != c) ++j;
      break;
    }
    if (j == m) break;
  }
  cout << res << '\n';
}
0