結果

問題 No.1192 半部分列
ユーザー kk
提出日時 2021-04-03 01:01:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,312 bytes
コンパイル時間 2,738 ms
コンパイル使用メモリ 201,344 KB
実行使用メモリ 38,304 KB
最終ジャッジ日時 2023-08-25 15:30:00
合計ジャッジ時間 6,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,764 KB
testcase_01 AC 2 ms
5,504 KB
testcase_02 AC 2 ms
5,504 KB
testcase_03 AC 2 ms
5,504 KB
testcase_04 AC 2 ms
5,360 KB
testcase_05 AC 2 ms
5,520 KB
testcase_06 AC 249 ms
38,304 KB
testcase_07 TLE -
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 #

#include <bits/stdc++.h>

using namespace std;

int nxt[100000][26];
int mxt[100000][26];

string dfs(int i, int n, int j, int m, char c) {
  if (i >= n || nxt[i][c - 'a'] == n) return "";

  string ret = string(1, c);
  if (j >= m || mxt[j][c - 'a'] == m) return ret;

  i = nxt[i][c - 'a'];
  j = mxt[j][c - 'a'];
  for (char d = 'a'; d <= 'z'; d++) {
    string tmp = dfs(i+1, n, j+1, m, d);
    if (tmp.size()) {
      ret += tmp;
      return ret;
    }
  }
  return "";
}

string solve(string s, string t) {
  int n = s.length();
  int m = t.length();

  for (int i = 0; i < 26; i++) {
    nxt[n-1][i] = n;
    mxt[m-1][i] = m;
  }
  nxt[n-1][s[n-1]-'a'] = n-1;
  mxt[m-1][t[m-1]-'a'] = m-1;

  for (int i = n-2; i >= 0; i--) {
    for (int j = 0; j < 26; j++)
      nxt[i][j] = nxt[i+1][j];
    nxt[i][s[i]-'a'] = i;
  }

  for (int i = m-2; i >= 0; i--) {
    for (int j = 0; j < 26; j++)
      mxt[i][j] = mxt[i+1][j];
    mxt[i][t[i]-'a'] = i;
  }
    
  for (char c = 'a'; c <= 'z'; c++) {
    string s = dfs(0, n, 0, m, c);
    if (s.length())
      return s;
  }
  return string();
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s, t;
  cin >> s >> t;
  string ret = solve(s, t);
  if (ret.length())
    cout << ret << endl;
  else
    cout << -1 << endl;
  
  return 0;
}
0