結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2020-08-22 16:27:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| コード長 | 970 bytes |
| コンパイル時間 | 3,295 ms |
| コンパイル使用メモリ | 250,128 KB |
| 最終ジャッジ日時 | 2025-01-13 10:11:15 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/extc++.h>
#ifndef DUMP
#define DUMP(...) (void)0
#endif
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
string s, t;
cin >> s >> t;
int n = size(s), m = size(t);
vector<int> p(n + 1);
p[n] = m;
for (int i = n; i--;) {
p[i] = p[i + 1] - 1;
while (p[i] >= 0 and t[p[i]] != s[i]) --p[i];
}
if (p[0] >= 0) {
cout << "-1\n";
exit(0);
}
vector<array<int, 26>> nxt(n + 1);
nxt[n].fill(n);
for (int i = n; i--;) {
nxt[i] = nxt[i + 1];
nxt[i][s[i] - 'a'] = i;
}
string res;
int i = 0, j = 0;
while (true) {
DUMP(i, j);
for (char c = 'a'; c <= 'z'; ++c) {
if (p[nxt[i][c - 'a']] >= j) continue;
res += c;
i = nxt[i][c - 'a'] + 1;
while (j < m and t[j] != c) ++j;
if (j == m) {
cout << res << '\n';
exit(0);
}
++j;
break;
}
}
cout << res << '\n';
}
risujiroh