結果

問題 No.1192 半部分列
ユーザー 沙耶花沙耶花
提出日時 2020-08-22 17:46:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 201,472 KB
実行使用メモリ 30,592 KB
最終ジャッジ日時 2024-04-23 11:36:01
合計ジャッジ時間 3,184 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 38 ms
30,592 KB
testcase_07 AC 34 ms
30,348 KB
testcase_08 AC 35 ms
30,336 KB
testcase_09 AC 33 ms
29,312 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 35 ms
30,336 KB
testcase_13 AC 15 ms
15,360 KB
testcase_14 AC 21 ms
20,608 KB
testcase_15 AC 19 ms
19,456 KB
testcase_16 AC 14 ms
15,104 KB
testcase_17 AC 20 ms
19,712 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 6 ms
7,936 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 17 ms
17,024 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 33 ms
30,336 KB
testcase_24 AC 6 ms
8,192 KB
testcase_25 AC 14 ms
14,720 KB
testcase_26 AC 14 ms
14,976 KB
testcase_27 AC 15 ms
16,384 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