結果

問題 No.1192 半部分列
ユーザー 沙耶花沙耶花
提出日時 2020-08-22 17:46:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 204,616 KB
実行使用メモリ 30,540 KB
最終ジャッジ日時 2023-08-05 14:29:36
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 44 ms
30,540 KB
testcase_07 AC 40 ms
30,228 KB
testcase_08 AC 40 ms
30,228 KB
testcase_09 AC 39 ms
29,312 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 39 ms
30,256 KB
testcase_13 AC 19 ms
15,228 KB
testcase_14 AC 26 ms
20,372 KB
testcase_15 AC 24 ms
19,096 KB
testcase_16 AC 18 ms
14,964 KB
testcase_17 AC 24 ms
19,332 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 8 ms
7,888 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 21 ms
16,764 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 40 ms
30,228 KB
testcase_24 AC 8 ms
7,876 KB
testcase_25 AC 18 ms
14,568 KB
testcase_26 AC 18 ms
14,760 KB
testcase_27 AC 20 ms
16,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0