結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2020-08-22 17:46:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 1,090 bytes |
| コンパイル時間 | 3,220 ms |
| コンパイル使用メモリ | 197,960 KB |
| 最終ジャッジ日時 | 2025-01-13 11:02:21 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005
int main(){
string S,T;
cin>>S>>T;
vector<vector<int>> nS(S.size()+1),nT(T.size()+1);
{
vector<int> now(26,Inf);
for(int i=S.size();i>=0;i--){
nS[i] = now;
if(i!=0){
now[S[i-1]-'a']=i;
}
}
}
{
vector<int> now(26,Inf);
for(int i=T.size();i>=0;i--){
nT[i] = now;
if(i!=0){
now[T[i-1]-'a']=i;
}
}
}
vector<int> ind(T.size(),Inf);
int pos = S.size();
for(int i=T.size()-1;i>=0;i--){
if(pos!=0&&T[i]==S[pos-1]){
pos--;
}
ind[i] = pos;
}
string ans = "";
int posS = 0,posT = 0;
while(true){
bool f = false;
for(int i=0;i<26;i++){
if(nS[posS][i]==Inf)continue;
if(nT[posT][i]==Inf){
ans += 'a'+i;
goto L;
}
int s = nS[posS][i]-1;
int t = nT[posT][i]-1;
if(ind[t]<=s)continue;
posS = s+1;
posT = t+1;
ans += 'a'+i;
f=true;
break;
}
if(!f)break;
}
L:;
if(ans==""){
cout<<-1<<endl;
}
else cout<<ans<<endl;
return 0;
}
沙耶花