結果

問題 No.1192 半部分列
ユーザー mugen_1337mugen_1337
提出日時 2020-08-27 03:25:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,533 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 201,072 KB
実行使用メモリ 43,776 KB
最終ジャッジ日時 2024-04-25 04:28:26
合計ジャッジ時間 4,336 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 WA -
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 59 ms
43,776 KB
testcase_09 AC 57 ms
41,728 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 60 ms
43,520 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 33 ms
26,240 KB
testcase_16 AC 25 ms
19,840 KB
testcase_17 AC 33 ms
25,344 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 10 ms
10,240 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 39 ms
29,952 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 14 ms
12,544 KB
testcase_25 AC 32 ms
25,600 KB
testcase_26 AC 33 ms
25,856 KB
testcase_27 AC 30 ms
23,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


//ret[i][j] : i以降の文字jが登場する最初のindex
vector<vector<int>> fillnxt(string s){
    int n=(int)s.size();
    vector<vector<int>> ret(n+1,vector<int>(26,INF));
    for(int i=n-1;i>=0;i--){
        rep(j,26) ret[i][j]=ret[i+1][j];
        ret[i][s[i]-'a']=i;
    }
    return ret;
}

signed main(){
    
    string s,t;cin>>s>>t;
    int n=(int)s.size(),m=(int)t.size();

    auto ns=fillnxt(s);
    auto nt=fillnxt(t);
    // s[i~n)をt[j~m)で作れる
    // v[i]=j, 作れないなら-1
    vector<vector<int>> pt(m+1,vector<int>(26,-1));
    rep(i,m+1){
        if(i)rep(j,26)pt[i][j]=pt[i-1][j];
        if(i<m) pt[i][t[i]-'a']=i;
    }
    vector<int> v(n+1,-1);
    v[n]=m;
    for(int i=n-1;i>=0;i--){
        if(v[i+1]>=0)v[i]=pt[v[i+1]][s[i]-'a'];
    }

    if(v[0]>=0){
        cout<<-1<<endl;
        return 0;
    }

    string res="";
    for(int i=0,j=0;i<n;){
        rep(k,26){
            int nj=nt[j][k],ni=ns[i][k];
            if(ni==INF){
                continue;
            }
            if(nj==INF){
                cout<<res<<char('a'+k)<<endl;
                return 0;
            }

            if(v[ni]>=nj)continue;
            res.push_back('a'+k);
            i=ni+1,j=nj+1;
            break;
        }
    }

    cout<<-1<<endl;
    return 0;
}
0