結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
Forested
|
| 提出日時 | 2020-08-05 18:25:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,063 bytes |
| コンパイル時間 | 683 ms |
| コンパイル使用メモリ | 75,248 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-17 08:11:47 |
| 合計ジャッジ時間 | 4,346 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 WA * 3 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'];
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;
}
Forested