結果

問題 No.1192 半部分列
ユーザー square1001square1001
提出日時 2020-08-22 14:09:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,135 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 77,828 KB
実行使用メモリ 30,592 KB
最終ジャッジ日時 2024-04-23 08:32:36
合計ジャッジ時間 1,858 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 39 ms
30,592 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 21 ms
20,608 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 18 ms
16,640 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 WA -
testcase_24 AC 6 ms
8,064 KB
testcase_25 AC 14 ms
14,592 KB
testcase_26 AC 14 ms
14,720 KB
testcase_27 AC 17 ms
16,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
vector<vector<int> > calc_next(string S) {
	int N = S.size();
	vector<vector<int> > dp(N + 1, vector<int>(26, inf));
	for (int i = N - 1; i >= 0; --i) {
		dp[i] = dp[i + 1];
		dp[i][S[i] - 'a'] = i;
	}
	return dp;
}
int main() {
	string S, T;
	cin >> S >> T;
	int LS = S.size(), LT = T.size();
	vector<int> dp(LS + 1); dp[LS] = LT;
	int ptr = LT;
	for (int i = LS - 1; i >= 0; --i) {
		while (ptr != -1) {
			--ptr;
			if (ptr != -1 && S[i] == T[ptr]) break;
		}
		dp[i] = ptr;
	}
	vector<vector<int> > ns = calc_next(S);
	vector<vector<int> > nt = calc_next(T);
	string ans;
	int posa = 0, posb = 0;
	while (true) {
		bool found = false;
		for (int i = 0; i < 26; ++i) {
			if (ns[posa][i] != inf && (posb == inf || dp[ns[posa][i] + 1] <= nt[posb][i])) {
				posa = ns[posa][i] + 1;
				posb = (posb != inf ? min(nt[posb][i] + 1, inf) : inf);
				ans += char('a' + i);
				found = true;
				break;
			}
		}
		if (!found) break;
	}
	if (ans.empty()) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}
0