結果

問題 No.1192 半部分列
ユーザー uzzyuzzy
提出日時 2020-09-01 00:30:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,876 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 192,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 11:43:35
合計ジャッジ時間 3,409 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

string S, T;
int N;
int M;
string keisan() {
	int A[100001];
	int saidai = N;
	int kari = M - 1;
	for (int i = N - 1; i >= 0; i--) {
		while (kari >= 0 && S[i] != T[kari]) {
			kari--;
		}
		A[i] = kari;
		kari--;
	}

	vector<int> SL[26];
	deque<int> TL[26];
	rep(j, N) {
		SL[S[j] - 'a'].pb(j);
	}
	rep(j, M) {
		TL[T[j] - 'a'].pb(j);
	}

	int i = 0, j = 0;
	string kotae;
	int iketa = 1;
	while (iketa) {
		iketa = 0;
		rep(p, 26) {
			auto itr = lower_bound(SL[p].begin(), SL[p].end(), i);
			if (itr == SL[p].end()) continue;

			int ind = *itr;
			int ue = A[ind];

			while (TL[p].size() && TL[p].front() < j) TL[p].pop_front();
			if (TL[p].size() == 0) {
				kotae += char('a' + p);
				//co(kotae);
				return kotae;
			}
			if (TL[p].front() > ue) {
				kotae += char('a' + p);
				i = ind + 1;
				j = TL[p].front() + 1;
				TL[p].pop_front();
				iketa = 1;
				break;
			}
		}
	}
	return "-1";
	//co(-1);
}

bool bubun(string tmp, string aite) {
	int n = tmp.size();
	int j = 0;
	int OK = 1;
	rep(i, n) {
		while (j < aite.size() && tmp[i] != aite[j]) j++;
		if (j == aite.size()) {
			OK = 0;
		}
		else j++;
	}
	return OK;
}

//vector<string> kotae;
//string kari;
//string keisan2() {
//
//}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	cin >> S >> T;
	N = S.size();
	M = T.size();


	co(keisan());







	Would you please return 0;
}
0