結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-22 15:52:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,304 bytes |
| コンパイル時間 | 721 ms |
| コンパイル使用メモリ | 74,340 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-15 10:01:39 |
| 合計ジャッジ時間 | 4,212 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<vector<int>> getNext(const string& s){
vector<vector<int>> res(s.size(), vector<int>(26, s.size()));
vector<int> last(26, s.size()+1);
for(int i=s.size()-1;i>=0;i--){
last[s[i]-'a'] = i+1;
for(int j=0;j<26;j++) res[i][j] = last[j];
}
return res;
}
string solve(const string& S, const string& T){
auto nextS = getNext(S);
auto nextT = getNext(T);
vector<int> dp(T.size()+1, S.size());
for(int i=T.size()-1;i>=0;i--){
dp[i] = dp[i+1];
if(dp[i] == 0) return "-1";
if(S[dp[i]-1] == T[i]) --dp[i];
}
int posS = 0, posT = 0;
string res = "";
while(posS < S.size()){
for(int i=0;i<26;i++){
int ns = nextS[posS][i];
int nt = (posT < T.size() ? nextT[posT][i] : T.size()+1);
if(ns > S.size()) continue;
if(nt > T.size()){
res += 'a'+i;
return res;
}
if(dp[nt] > ns){
res += 'a'+i;
posS = ns;
posT = nt;
break;
}
}
}
return res;
}
int main(){
string S, T;
while(cin >> S >> T){
cout << solve(S, T) << endl;
}
}