結果

問題 No.1192 半部分列
ユーザー leaf_1415leaf_1415
提出日時 2020-08-22 17:01:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 2,129 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 83,376 KB
実行使用メモリ 106,104 KB
最終ジャッジ日時 2024-04-23 11:05:42
合計ジャッジ時間 2,213 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 57 ms
106,000 KB
testcase_07 AC 40 ms
106,104 KB
testcase_08 AC 40 ms
106,104 KB
testcase_09 AC 38 ms
101,832 KB
testcase_10 AC 2 ms
9,700 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 49 ms
105,988 KB
testcase_13 AC 23 ms
53,924 KB
testcase_14 AC 29 ms
71,936 KB
testcase_15 AC 25 ms
63,900 KB
testcase_16 AC 21 ms
47,908 KB
testcase_17 AC 24 ms
61,696 KB
testcase_18 AC 2 ms
7,660 KB
testcase_19 AC 9 ms
21,120 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 26 ms
65,280 KB
testcase_22 AC 4 ms
8,680 KB
testcase_23 AC 40 ms
105,792 KB
testcase_24 AC 11 ms
29,372 KB
testcase_25 AC 22 ms
55,296 KB
testcase_26 AC 24 ms
60,076 KB
testcase_27 AC 27 ms
53,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

string s, t;
llint preS[100005][26], preT[100005][26];
llint succS[100005][26], succT[100005][26];
llint dp[100005][26], ub[100005];

void make(string &s, llint pre[100005][26], llint succ[100005][26])
{
	llint N = (int)s.size()-1;
	for(int j = 0; j < 26; j++) succ[N][j] = N+1;
	for(int i = N-1; i >= 0; i--){
		for(int j = 0; j < 26; j++) succ[i][j] = succ[i+1][j];
		succ[i][s[i+1]-'a'] = i+1;
	}
	
	for(int j = 0; j < 26; j++) pre[1][j] = 0;
	for(int i = 2; i <= N+2; i++){
		for(int j = 0; j < 26; j++) pre[i][j] = pre[i-1][j];
		if(i-1 <= N) pre[i][s[i-1]-'a'] = i-1;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> s >> t;
	llint S = s.size(), T = t.size();
	s = "#" + s, t = "#" + t;
	
	make(s, preS, succS), make(t, preT, succT);
	
	for(int j = 0; j < 26; j++) dp[T+1][j] = S;
	ub[T+1] = S+1;
	
	for(int i = T; i >= 0; i--){
		for(int j = 0; j < 26; j++){
			llint r = ub[succT[i][j]];
			if(r < 0) dp[i][j] = -1;
			else dp[i][j] = preS[r+1][j]-1;
		}
		ub[i] = -1;
		for(int j = 0; j < 26; j++) ub[i] = max(ub[i], dp[i][j]);
	}
	
	/*for(int i = 1; i <= T+1; i++){
		for(int j = 0; j < 3; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	if(ub[0] < 0){
		cout << -1 << endl;
		return 0;
	}
	
	string ans; llint p = 0, q = 0;
	while(q <= T){
		///cout << p << " " << q << " " << ans << endl;
		for(int i = 0; i < 26; i++){
			if(dp[q][i] >= p){
				ans += i + 'a';
				q = succT[q][i];
				p = succS[p][i];
				break;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}
0