結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
	}
	cout << dp[0] << endl;
	return 0;
	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 = min(nt[posb][i] + 1, inf);
				ans += char('a' + i);
				found = true;
				break;
			}
		}
		if (!found) break;
	}
	if (ans.empty()) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}
0