結果

問題 No.1192 半部分列
ユーザー yukudoyukudo
提出日時 2020-08-31 21:08:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,834 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 168,460 KB
実行使用メモリ 26,516 KB
最終ジャッジ日時 2024-04-28 11:10:29
合計ジャッジ時間 3,662 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 21 ms
13,824 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 9 ms
7,168 KB
testcase_25 AC 17 ms
12,032 KB
testcase_26 AC 18 ms
12,160 KB
testcase_27 AC 20 ms
13,696 KB
権限があれば一括ダウンロードができます

ソースコード

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);

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

  // 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;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

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