結果

問題 No.1192 半部分列
ユーザー yukudo
提出日時 2020-08-31 21:16:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,856 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 168,712 KB
実行使用メモリ 24,448 KB
最終ジャッジ日時 2024-11-17 02:25:39
合計ジャッジ時間 3,488 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 112345;

int nextS[MAX_N][26];
int nextT[MAX_N][26];
int B[MAX_N];

void make(const string S, int next[MAX_N][26]) {
  for (int c = 0; c < 26; c++) {
    int l = S.size();
    next[S.size()][c] = l;
    for (int i = S.size() - 1; i >= 0; i--) {
      if (S[i] == 'a' + c) l = i;
      next[i][c] = l;
    }
  }
}

int main2() {
  string S, T;
  cin >> S >> T;

  const int N = S.size();
  const int M = T.size();

  make(S, nextS);
  make(T, nextT);

  {
    B[S.size()] = T.size();
    int j = T.size();
    for (int i = S.size() - 1; i >= 0; i--) {
      if (j >= 0) j--;
      while (j >= 0 && S[i] != T[j]) j--;
      B[i] = j;
    }
  }

  // cout << S << endl;
  // cout << T << endl;
  // pv(B, B+S.size() + 1);

  if (B[0] != -1) {
    cout << -1 << endl;
    return 0;
  }

  string ans = "";
  int ii = 0, jj = 0;
  for (; ii < (int)S.size() && jj <= (int)T.size(); ) {
    for (int c = 0; c < 26; c++) {
      int n_ii = nextS[ii][c];
      int n_jj = nextT[jj][c];
      if (n_ii >= (int)S.size()) continue;
      if (n_jj <= B[n_ii]) continue;
      ans += (char)('a' + c);
      ii = n_ii + 1;
      jj = n_jj + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
0