結果

問題 No.1192 半部分列
ユーザー MayimgMayimg
提出日時 2020-08-25 18:22:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,342 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 200,252 KB
実行使用メモリ 35,840 KB
最終ジャッジ日時 2024-04-24 04:44:25
合計ジャッジ時間 5,973 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 TLE -
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 #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  vector<int> ls(n + 1, -1);
  for (int i = n - 1, j = m - 1; i >= 0; i--) {
    while (j >= 0 && t[j] != s[i]) j--;
    ls[i] = j;
  }
  if (ls[0] != -1) {
    cout << -1 << endl;
    return 0;
  }
  vector<vector<int>> as(n + 1, vector<int>(26, -1));
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (j == s[i] - 'a') {
        as[i][j] = i;
      } else {
        if (i < n - 1) as[i][j] = as[i + 1][j];
      }
    }
  }
  vector<vector<int>> at(m + 1, vector<int>(26, -1));
  for (int i = m - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (j == t[i] - 'a') {
        at[i][j] = i;
      } else {
        if (i < m - 1) at[i][j] = at[i + 1][j];
      }
    }
  }
  string ans;
  int i = 0, j = 0;
  while (i < n) {
    for (int c = 0; c < 26; c++) {
      if (as[i][c] == -1) continue;
      if (at[j][c] == -1) {
        ans += c + 'a';
        goto done; 
      }
      int a = as[i][c];
      int b = at[j][c];
      if (ls[a] == -1 || ls[a] > b) {
        ans += c + 'a';
        i = a + 1;
        j = b + 1;
        break;
      }
    }
  }
  done:;
  cout << ans << endl;
  return 0;
}
0