結果

問題 No.1192 半部分列
ユーザー yukudoyukudo
提出日時 2020-08-31 21:20:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,865 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 168,728 KB
実行使用メモリ 27,136 KB
最終ジャッジ日時 2024-04-28 11:12:53
合計ジャッジ時間 3,019 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
26,732 KB
testcase_01 AC 9 ms
26,732 KB
testcase_02 AC 8 ms
26,732 KB
testcase_03 AC 9 ms
26,856 KB
testcase_04 AC 8 ms
26,752 KB
testcase_05 AC 9 ms
26,752 KB
testcase_06 AC 44 ms
26,864 KB
testcase_07 AC 42 ms
26,992 KB
testcase_08 AC 42 ms
26,988 KB
testcase_09 AC 38 ms
27,136 KB
testcase_10 AC 8 ms
26,728 KB
testcase_11 AC 9 ms
26,732 KB
testcase_12 AC 39 ms
27,048 KB
testcase_13 AC 24 ms
26,864 KB
testcase_14 AC 30 ms
27,044 KB
testcase_15 AC 28 ms
27,008 KB
testcase_16 AC 23 ms
26,880 KB
testcase_17 AC 28 ms
27,008 KB
testcase_18 AC 9 ms
26,752 KB
testcase_19 AC 15 ms
26,752 KB
testcase_20 AC 9 ms
26,624 KB
testcase_21 AC 24 ms
26,860 KB
testcase_22 AC 8 ms
26,624 KB
testcase_23 AC 39 ms
27,008 KB
testcase_24 AC 14 ms
26,880 KB
testcase_25 AC 21 ms
26,880 KB
testcase_26 AC 22 ms
26,880 KB
testcase_27 AC 25 ms
26,880 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() {

  CLR(nextS, 0);
  CLR(nextT, 0);
  CLR(B, 0);

  string S, T;
  cin >> S >> T;

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

int main() {

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