結果

問題 No.1192 半部分列
ユーザー chocopuuchocopuu
提出日時 2020-08-23 14:50:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,883 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 201,884 KB
実行使用メモリ 53,068 KB
最終ジャッジ日時 2024-04-23 17:49:28
合計ジャッジ時間 3,364 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 62 ms
53,068 KB
testcase_07 AC 57 ms
53,068 KB
testcase_08 AC 58 ms
53,064 KB
testcase_09 AC 55 ms
51,304 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 57 ms
53,068 KB
testcase_13 AC 24 ms
25,216 KB
testcase_14 AC 37 ms
35,072 KB
testcase_15 AC 34 ms
33,436 KB
testcase_16 AC 23 ms
25,088 KB
testcase_17 AC 32 ms
33,976 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 11 ms
12,160 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 26 ms
27,520 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 58 ms
53,056 KB
testcase_24 AC 10 ms
11,776 KB
testcase_25 AC 22 ms
23,680 KB
testcase_26 AC 22 ms
23,936 KB
testcase_27 AC 27 ms
27,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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 INF = 1e18;

vector<vector<int> > calcNext(const string &S) {
	int n = (int)S.size();
	vector<vector<int> > res(n+1, vector<int>(26, n));
	for (int i = n-1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i+1][j];
		res[i][S[i]-'a'] = i;
	}
	return res;
}

vector<int> makeSubString(const string &s, const string &t) {
	vector<int>ret;
	int now = 0;
	for(auto e: s) {
		while(now < t.size() && e != t[now]) ++now;
		++now;
		ret.emplace_back(now);
	}
	return ret;
}

signed main(){
	string s, t;
	cin >> s >> t;
	auto nextS = calcNext(s);
	auto nextT = calcNext(t);
	reverse(ALL(s));
	reverse(ALL(t));
	auto dp = makeSubString(s, t);
	reverse(ALL(s));
	reverse(ALL(t));
	reverse(ALL(dp));

	int Scur = 0, Tcur = 0;
	string ans;
	while(Scur < s.size()) {
		int nextc = -1;
		REP(d, 26) if(nextS[Scur][d] < s.size()) {
			if(dp[nextS[Scur][d]] + Tcur > t.size()) {
				nextc = d;
				break;
			}
		}
		if(nextc < 0) {
			out(-1);
			return 0;
		}
		ans += 'a' + nextc;
		Scur = nextS[Scur][nextc] + 1;
		Tcur = nextT[Tcur][nextc] + 1;
		if(Tcur > t.size()) break;
	}
	out(ans);
}
0