結果

問題 No.1192 半部分列
ユーザー risujirohrisujiroh
提出日時 2020-08-22 16:27:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 3,796 ms
コンパイル使用メモリ 252,692 KB
実行使用メモリ 14,552 KB
最終ジャッジ日時 2024-04-23 10:33:10
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 9 ms
14,552 KB
testcase_07 AC 7 ms
14,448 KB
testcase_08 AC 6 ms
14,336 KB
testcase_09 AC 6 ms
14,192 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 7 ms
14,464 KB
testcase_13 AC 3 ms
6,016 KB
testcase_14 AC 5 ms
9,088 KB
testcase_15 AC 4 ms
10,872 KB
testcase_16 AC 5 ms
8,924 KB
testcase_17 AC 5 ms
12,392 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,632 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 6 ms
14,464 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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) {
    DUMP(i, j);
    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;
      if (j == m) {
        cout << res << '\n';
        exit(0);
      }
      ++j;
      break;
    }
  }
  cout << res << '\n';
}
0