結果

問題 No.1192 半部分列
ユーザー risujirohrisujiroh
提出日時 2020-08-22 16:27:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 4,180 ms
コンパイル使用メモリ 261,720 KB
実行使用メモリ 14,540 KB
最終ジャッジ日時 2023-08-05 13:20:56
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 11 ms
14,372 KB
testcase_07 AC 7 ms
14,220 KB
testcase_08 AC 8 ms
14,540 KB
testcase_09 AC 7 ms
14,132 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 8 ms
14,232 KB
testcase_13 AC 4 ms
5,840 KB
testcase_14 AC 5 ms
8,904 KB
testcase_15 AC 6 ms
10,652 KB
testcase_16 AC 4 ms
9,168 KB
testcase_17 AC 6 ms
12,160 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 3 ms
5,364 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 7 ms
14,184 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,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