結果
| 問題 | 
                            No.1192 半部分列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Forested
                         | 
                    
| 提出日時 | 2020-08-05 18:28:56 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,133 bytes | 
| コンパイル時間 | 680 ms | 
| コンパイル使用メモリ | 73,908 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-17 08:20:26 | 
| 合計ジャッジ時間 | 3,773 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 5 RE * 20 | 
ソースコード
#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'] + 1;
            if (now == ts + 1) break;
        }
        if (now == ts + 1) 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;
}
            
            
            
        
            
Forested