結果
| 問題 | 
                            No.1192 半部分列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tnakao0123
                         | 
                    
| 提出日時 | 2020-08-24 16:59:38 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 13 ms / 2,000 ms | 
| コード長 | 1,680 bytes | 
| コンパイル時間 | 868 ms | 
| コンパイル使用メモリ | 96,164 KB | 
| 実行使用メモリ | 24,512 KB | 
| 最終ジャッジ日時 | 2024-11-06 10:26:10 | 
| 合計ジャッジ時間 | 1,918 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
/* -*- 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++) {
	int i1 = scs[i][c] + 1, j1 = tcs[j][c] + 1;
	if (i1 <= n && sbss[i1] < j1) {
	  //printf("w[%d]=%c, i=%d->%d, j=%d->%d\n", k, 'a' + c, i, i1, j, j1);
	  w[k++] = 'a' + c;
	  i = i1, j = j1;
	  break;
	}
      }
    }
    if (j < INF)
      for (int c = 0; c < 26; c++)
	if (scs[i][c] < n) {
	  w[k++] = 'a' + c;
	  break;
	}
    puts(w);
  }
  return 0;
}
            
            
            
        
            
tnakao0123