結果

問題 No.1192 半部分列
ユーザー SSRSSSRS
提出日時 2020-08-22 17:24:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,458 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 168,960 KB
実行使用メモリ 30,464 KB
最終ジャッジ日時 2024-04-23 11:20:15
合計ジャッジ時間 3,238 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 43 ms
30,464 KB
testcase_09 AC 39 ms
29,440 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 40 ms
30,336 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 26 ms
19,584 KB
testcase_16 AC 18 ms
15,104 KB
testcase_17 AC 25 ms
19,968 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 9 ms
7,936 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main(){
  string S;
  cin >> S;
  string T;
  cin >> T;
  int N = S.size();
  int M = T.size();
  vector<int> p(N + 1, -1);
  p[N] = M;
  int ps = M - 1;
  for (int i = N - 1; i >= 0; i--){
    while (T[ps] != S[i]){
      ps--;
      if (ps == -1){
        break;
      }
    }
    if (ps == -1){
      break;
    } else {
      p[i] = ps;
    }
  }
  if (p[0] != -1){
    cout << -1 << endl;
  } else {
    vector<vector<int>> next1(N + 1, vector<int>(26, N));
    for (int i = N - 1; i >= 0; i--){
      next1[i] = next1[i + 1];
      next1[i][S[i] - 'a'] = i;
    }
    vector<vector<int>> next2(M + 1, vector<int>(26, M));
    for (int i = M - 1; i >= 0; i--){
      next2[i] = next2[i + 1];
      next2[i][T[i] - 'a'] = i;
    }
    string ans = "";
    int p1 = 0, p2 = 0;
    while (1){
      bool ok = false;
      bool ok2 = false;
      for (int i = 0; i < 26; i++){
        if (next1[p1][i] != N){
          if (next2[p2][i] == M){
            ans += 'a' + i;
            ok = true;
            break;
          } else {
            int p3 = next1[p1][i] + 1;
            int p4 = next2[p2][i] + 1;
            if (p[p3] < p4){
              ans += 'a' + i;
              p1 = p3;
              p2 = p4;
              ok2 = true;
              break;
            }
          }
        }
      }
      if (ok || !ok2){
        break;
      }
    }
    cout << ans << endl;
  }
}
0