結果

問題 No.1192 半部分列
ユーザー e869120e869120
提出日時 2021-03-05 18:54:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,443 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 85,708 KB
実行使用メモリ 24,576 KB
最終ジャッジ日時 2024-04-16 06:58:18
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_07 WA -
testcase_08 AC 24 ms
24,576 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 24 ms
24,448 KB
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 AC 13 ms
13,824 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 6 ms
7,168 KB
testcase_25 AC 11 ms
12,288 KB
testcase_26 AC 11 ms
12,288 KB
testcase_27 AC 12 ms
13,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

string S, T;
int cs[100009][26];
int ct[100009][26];
int dp[100009];

int main() {
	// Step #1. 入力
	cin >> S >> T;

	// Step #2. S について計算
	for (int i = 0; i < 26; i++) cs[S.size()][i] = S.size();
	for (int i = S.size() - 1; i >= 0; i--) {
		for (int j = 0; j < 26; j++) cs[i][j] = cs[i + 1][j];
		cs[i][S[i] - 'a'] = i;
	}

	// Step #3. T について計算
	for (int i = 0; i < 26; i++) ct[T.size()][i] = T.size();
	for (int i = T.size() - 1; i >= 0; i--) {
		for (int j = 0; j < 26; j++) ct[i][j] = ct[i + 1][j];
		ct[i][T[i] - 'a'] = i;
	}

	// Step #4. 貪欲法
	dp[S.size()] = T.size(); int cx = T.size() - 1;
	for (int i = S.size() - 1; i >= 0; i--) {
		while (cx >= 0 && T[cx] != S[i]) cx--;
		dp[i] = cx;
	}

	// Step #5. 辞書順貪欲
	int px = 0, qx = 0;
	string str = "";
	while (px < S.size()) {
		bool flag = false;
		for (int i = 0; i < 26; i++) {
			int nex1 = cs[px][i];
			int nex2 = ct[qx][i];
			if (nex1 == S.size()) continue;
			if (dp[nex1 + 1] < nex2 + 1) {
				flag = true;
				str += ('a' + i);
				px = nex1 + 1;
				qx = nex2 + 1;
				break;
			}
		}
		if (flag == false) break;
	}

	// Step #6. 出力
	if (str == "") cout << "-1" << endl;
	else cout << str << endl;
	return 0;
}
0