結果
| 問題 | 
                            No.1192 半部分列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             chocopuu
                         | 
                    
| 提出日時 | 2020-08-23 14:47:47 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,811 bytes | 
| コンパイル時間 | 2,297 ms | 
| コンパイル使用メモリ | 199,452 KB | 
| 最終ジャッジ日時 | 2025-01-13 12:31:57 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 WA * 5 | 
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;
vector<vector<int> > calcNext(const string &S) {
	int n = (int)S.size();
	vector<vector<int> > res(n+1, vector<int>(26, n));
	for (int i = n-1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i+1][j];
		res[i][S[i]-'a'] = i;
	}
	return res;
}
vector<int> makeSubString(const string &s, const string &t) {
	vector<int>ret;
	int now = 0;
	for(auto e: s) {
		while(now < t.size() && e != t[now]) ++now;
		++now;
		ret.emplace_back(now);
	}
	return ret;
}
signed main(){
	string s, t;
	cin >> s >> t;
	auto nextS = calcNext(s);
	auto nextT = calcNext(t);
	auto dp = makeSubString(s, t);
	reverse(ALL(dp));
	int Scur = 0, Tcur = 0;
	string ans;
	while(Scur < s.size()) {
		int nextc = -1;
		REP(d, 26) if(nextS[Scur][d] < s.size()) {
			if(dp[nextS[Scur][d]] + Tcur > t.size()) {
				nextc = d;
				break;
			}
		}
		if(nextc < 0) {
			out(-1);
			return 0;
		}
		ans += 'a' + nextc;
		Scur = nextS[Scur][nextc] + 1;
		Tcur = nextT[Tcur][nextc] + 1;
		if(Tcur > t.size()) break;
	}
	out(ans);
}
            
            
            
        
            
chocopuu