結果

問題 No.1192 半部分列
ユーザー definedefine
提出日時 2020-08-05 14:20:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,324 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 200,708 KB
実行使用メモリ 45,080 KB
最終ジャッジ日時 2023-10-14 23:30:35
合計ジャッジ時間 3,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,532 KB
testcase_01 AC 2 ms
5,496 KB
testcase_02 AC 2 ms
5,460 KB
testcase_03 AC 2 ms
5,416 KB
testcase_04 AC 2 ms
5,416 KB
testcase_05 AC 2 ms
5,464 KB
testcase_06 AC 22 ms
45,068 KB
testcase_07 AC 18 ms
44,956 KB
testcase_08 AC 18 ms
45,080 KB
testcase_09 AC 18 ms
44,644 KB
testcase_10 AC 2 ms
5,532 KB
testcase_11 AC 2 ms
5,416 KB
testcase_12 AC 18 ms
44,960 KB
testcase_13 AC 10 ms
25,400 KB
testcase_14 AC 13 ms
33,872 KB
testcase_15 AC 12 ms
29,904 KB
testcase_16 AC 9 ms
23,580 KB
testcase_17 AC 12 ms
32,016 KB
testcase_18 AC 2 ms
5,476 KB
testcase_19 AC 6 ms
15,360 KB
testcase_20 AC 2 ms
5,464 KB
testcase_21 AC 10 ms
25,544 KB
testcase_22 AC 2 ms
5,828 KB
testcase_23 AC 19 ms
44,872 KB
testcase_24 AC 5 ms
13,120 KB
testcase_25 AC 9 ms
23,236 KB
testcase_26 AC 9 ms
23,500 KB
testcase_27 AC 10 ms
27,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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