結果

問題 No.1192 半部分列
ユーザー tnakao0123tnakao0123
提出日時 2020-08-24 13:56:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,576 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 91,288 KB
実行使用メモリ 29,744 KB
最終ジャッジ日時 2023-08-06 07:22:53
合計ジャッジ時間 4,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
29,744 KB
testcase_01 AC 2 ms
5,464 KB
testcase_02 AC 2 ms
5,472 KB
testcase_03 AC 2 ms
5,544 KB
testcase_04 AC 2 ms
5,536 KB
testcase_05 AC 2 ms
5,596 KB
testcase_06 TLE -
testcase_07 -- -
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 #

/* -*- coding: utf-8 -*-
 *
 * 1192.cc:  No.1192 半部分列 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

char s[MAX_N + 4], t[MAX_N + 4], w[MAX_N + 4];
int scs[MAX_N + 1][26], tcs[MAX_N + 1][26];
int sbss[MAX_N + 1];

/* subroutines */

void calccs(int n, char s[], int cs[][26]) {
  fill(cs[n], cs[n] + 26, INF);
  for (int i = n - 1; i >= 0; i--) {
    copy(cs[i + 1], cs[i + 1] + 26, cs[i]);
    cs[i][s[i] - 'a'] = i;
  }
}

/* main */

int main() {
  scanf("%s%s", s, t);
  int n = strlen(s), m = strlen(t);

  calccs(n, s, scs);
  calccs(m, t, tcs);

  sbss[n] = m;
  for (int i = n - 1, j = m - 1; i >= 0; i--) {
    while (j >= 0 && t[j] != s[i]) j--;
    sbss[i] = j;
    if (j >= 0) j--;
  }
  //for (int i = 0; i <= n; i++) printf("%d ", sbss[i]); putchar('\n');

  if (sbss[0] >= 0)
    puts("-1");
  else {
    int i = 0, j = 0, k = 0;
    for (; j < m;) {
      for (int c = 0; c < 26; c++)
	if (scs[i][c] < n && sbss[scs[i][c]] < 0) {
	  w[k++] = 'a' + c;
	  i = scs[i][c] + 1;
	  j = tcs[j][c] + 1;
	  break;
	}
    }

    for (int c = 0; c < 26; c++)
      if (scs[i][c] < n) {
	w[k++] = 'a' + c;
	break;
      }

    puts(w);
  }

  return 0;
}
0