結果

問題 No.1192 半部分列
ユーザー ForestedForested
提出日時 2020-08-05 18:25:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 73,952 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 09:43:46
合計ジャッジ時間 4,571 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cassert>
using namespace std;
const int alphabet_size = 26;

string s, t;

void solve() {
    int ss = (int)s.size(), ts = (int)t.size();
    vector<vector<int>> t_next(ts + 1, vector<int>(alphabet_size, ts));
    for (int i = ts - 1; i >= 0; --i) {
        for (int j = 0; j < alphabet_size; ++j) {
            t_next[i][j] = t_next[i + 1][j];
        }
        t_next[i][t[i] - 'a'] = i;
    }
    
    string ans = "zzzzzzzzzzzzzzzzzzzzzz";
    for (int bit = 0; bit < 1 << ss; ++bit) {
        if (!bit) continue;
        string str;
        for (int i = 0; i < ss; ++i) {
            if ((bit >> i) & 1) str.push_back(s[i]);
        }
        int now = 0;
        for (char c: str) now = t_next[now][c - 'a'];
        if (now == ts) ans = min(ans, str);
    }
    
    if (ans == "zzzzzzzzzzzzzzzzzzzzzz") cout << -1 << endl;
    else cout << ans << endl;
}

int main() {
    cin >> s >> t;
    
    // small case
    assert(s.size() < 20 && t.size() < 20);
    
    solve();
    return 0;
}
0