結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-05 14:59:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,381 bytes |
| コンパイル時間 | 1,945 ms |
| コンパイル使用メモリ | 194,708 KB |
| 最終ジャッジ日時 | 2025-01-12 14:54:50 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 RE * 6 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
template<class T> inline bool chmin(T &a, T b){
if(a>b){a=b;return true;}
return false;
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){a=b;return true;}
return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;
//Buffer Over Flow
string S,T;
int nexS[90005][26],nexT[90005][26];
int inc[90005];
signed main(){
cin>>S>>T;
assert(len(S)<=100000&&len(T)<=100000);
rep(i,26){
nexS[len(S)][i]=len(S);
nexT[len(T)][i]=len(T);
}
rev(i,len(S)){
rep(j,26)nexS[i][j]=nexS[i+1][j];
nexS[i][S[i]-'a']=i;
}
rev(i,len(T)){
rep(j,26)nexT[i][j]=nexT[i+1][j];
nexT[i][T[i]-'a']=i;
}
int now=len(T);inc[len(S)]=now;
rev(i,len(S)){
now=max(-1ll,now-1);
while(now>=0&&T[now]!=S[i])now--;
inc[i]=now;
}
if(inc[0]!=-1){
cout<<"-1\n";return 0;
}
string Ans;
int curS=0,curT=0;
while(curS<len(S)){
rep(i,26){
if(nexS[curS][i]==len(S))continue;
if(nexT[curT][i]==len(T)){
Ans+=('a'+i);
cout<<Ans<<endl;return 0;
}
if(inc[nexS[curS][i]+1]>=nexT[curT][i]+1)continue;
curS=nexS[curS][i]+1;
curT=nexT[curT][i]+1;
Ans+=('a'+i);
break;
}
}
}