結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-05 14:20:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 1,324 bytes |
| コンパイル時間 | 3,227 ms |
| コンパイル使用メモリ | 194,044 KB |
| 最終ジャッジ日時 | 2025-01-12 14:54:04 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#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;
string S,T;
int nexS[100005][26],nexT[100005][26];
int inc[100005];
signed main(){
cin>>S>>T;
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;
}
}
}