結果

問題 No.1192 半部分列
ユーザー 👑 jupirojupiro
提出日時 2020-10-21 10:52:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 2,237 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 136,340 KB
実行使用メモリ 30,852 KB
最終ジャッジ日時 2023-09-28 14:07:54
合計ジャッジ時間 3,025 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 36 ms
30,852 KB
testcase_07 AC 33 ms
30,676 KB
testcase_08 AC 33 ms
30,620 KB
testcase_09 AC 33 ms
29,592 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 33 ms
30,620 KB
testcase_13 AC 16 ms
15,372 KB
testcase_14 AC 22 ms
20,776 KB
testcase_15 AC 21 ms
19,600 KB
testcase_16 AC 16 ms
15,448 KB
testcase_17 AC 21 ms
20,036 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 8 ms
8,212 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 22 ms
16,556 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 33 ms
30,828 KB
testcase_24 AC 8 ms
7,856 KB
testcase_25 AC 19 ms
14,452 KB
testcase_26 AC 18 ms
14,456 KB
testcase_27 AC 20 ms
16,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 1100000;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s, t; cin >> s >> t;

	auto nextcharchter = [](string s)->vector<vector<int>> {
		int n = s.size();
		vector<vector<int>> ret(n + 1, vector<int>(26, n));
		for (int i = n - 1; i >= 0; i--) {
			if (i + 1 < n) {
				for (int j = 0; j < 26; j++) {
					ret[i][j] = ret[i + 1][j];
				}
			}
			ret[i][s[i] - 'a'] = i;
		}
		return ret;
	};
	auto ns = nextcharchter(s);
	auto nt = nextcharchter(t);

	vector<int> lst(s.size());
	{
		int cur = (int)t.size() - 1;
		for (int i = (int)s.size() - 1; i >= 0; i--) {
			while (cur >= 0 and t[cur] != s[i]) cur--;
			lst[i] = cur;
			if (cur >= 0) cur--;
		}
	}
	if (lst[0] != -1) {
		cout << -1 << endl;
		return 0;
	}
	string res;
	int sc = 0;
	int tc = 0;
	while (true) {
		for (int i = 0; i < 26; i++) {
			if (ns[sc][i] == s.size()) continue;
			if (nt[tc][i] == t.size()) {
				res += (char)(i + 'a');
				cout << res << "\n";
				exit(0);
			}
			if (lst[ns[sc][i]] >= nt[tc][i]) continue;
			res += (char)(i + 'a');
			sc = ns[sc][i] + 1;
			tc = nt[tc][i] + 1;
			break;
		}
	}
}
0