結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-08-23 22:39:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 2,302 bytes |
| コンパイル時間 | 775 ms |
| コンパイル使用メモリ | 85,028 KB |
| 実行使用メモリ | 24,384 KB |
| 最終ジャッジ日時 | 2024-10-15 19:23:52 |
| 合計ジャッジ時間 | 1,830 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
string S, T;
int substr_idx[100000];
int next_t[100005][26];
int next_s[100005][26];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> S >> T;
int cur_t = T.size()-1;
for(int i = S.size()-1; i >= 0; i--){
while(cur_t >= 0){
if(T[cur_t] == S[i]) break;
cur_t--;
}
substr_idx[i] = cur_t;
if(cur_t >= 0) cur_t--;
}
if(substr_idx[0] != -1){
cout << -1 << endl;
return 0;
}
// T
for(int i = 0; i < 26; i++){
next_t[T.size()-1][i] = T.size();
}
next_t[T.size()-1][T[T.size()-1]-'a'] = T.size()-1;
for(int i = T.size()-1; i >= 0; i--){
if(i == T.size()-1) continue;
for(int j = 0; j < 26; j++){
next_t[i][j] = next_t[i+1][j];
}
next_t[i][T[i]-'a'] = i;
}
// S
for(int i = 0; i < 26; i++){
next_s[S.size()-1][i] = S.size();
}
next_s[S.size()-1][S[S.size()-1]-'a'] = S.size()-1;
for(int i = S.size()-1; i >= 0; i--){
if(i == S.size()-1) continue;
for(int j = 0; j < 26; j++){
next_s[i][j] = next_s[i+1][j];
}
next_s[i][S[i]-'a'] = i;
}
int cur_s = 0; cur_t = 0;
string ans;
while(true){
if(cur_t > T.size()) break;
if(cur_t >= T.size()) {
for(int i = 0; i < 26; i++){
char c = 'a'+i;
int s = next_s[cur_s][i];
if(s < S.size()){
ans += c;
break;
}
}
break;
}
for(int i = 0; i < 26; i++){
int s = next_s[cur_s][i];
int t = next_t[cur_t][i];
char c = 'a'+i;
if(s < S.size() && t == T.size()) {
cur_t = t+1;
ans += c;
break;
}
if(s < S.size() && substr_idx[s] < t){
ans += c;
cur_s = s+1;
cur_t = t+1;
break;
}
}
}
cout << ans << endl;
}
milanis48663220