結果

問題 No.1192 半部分列
ユーザー carrot46carrot46
提出日時 2020-08-25 11:23:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,688 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 170,660 KB
実行使用メモリ 6,684 KB
最終ジャッジ日時 2024-04-24 04:16:01
合計ジャッジ時間 2,432 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    string T;
    cin>>S>>T;
    N = S.size(); M = T.size();
    mat memo(26, vec(0)), memo2(26, vec(0));
    vec len(M + 1, 0);
    rep(i,N) memo[S[i] - 'a'].push_back(i);
    rep(i,M) memo2[T[i] - 'a'].push_back(i);
    for(int i = M - 1, id = N - 1; i >= 0; --i){
        len[i] = len[i + 1];
        if(T[i] == (id >= 0 ? S[id] : '?')){
            ++len[i];
            --id;
        }
    }
    string ans = "";
    int sid = 0, tid = 0;
    bool stop = false;
    while(!stop){
        //cout<<sid<<' '<<tid<<endl;
        rep(i, 26){
            auto ite = lower_bound(ALL(memo[i]), sid);
            if(ite != memo[i].end()){
                auto ite2 = lower_bound(ALL(memo2[i]), tid);
                if(ite2 == memo2[i].end()){
                    stop = true;
                    ans.push_back(char('a' + i));
                    break;
                }else if(len[(*ite2) + 1] < (N - *ite) - 1){
                    sid = (*ite) + 1;
                    tid = (*ite2) + 1;
                    ans.push_back(char('a' + i));
                    break;
                }
            }
            if(i == 25) stop = true;
        }
    }
    cout<<(ans.empty() ? "-1" : ans)<<endl;
}
0