結果

問題 No.1192 半部分列
ユーザー chocoruskchocorusk
提出日時 2020-08-22 15:16:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,913 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 127,768 KB
実行使用メモリ 24,616 KB
最終ジャッジ日時 2024-04-23 09:38:56
合計ジャッジ時間 2,094 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
22,104 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 5 ms
21,980 KB
testcase_03 AC 5 ms
22,104 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 5 ms
22,100 KB
testcase_06 AC 22 ms
24,488 KB
testcase_07 AC 15 ms
24,580 KB
testcase_08 AC 14 ms
24,436 KB
testcase_09 AC 14 ms
24,504 KB
testcase_10 AC 5 ms
22,096 KB
testcase_11 AC 5 ms
22,100 KB
testcase_12 AC 16 ms
24,492 KB
testcase_13 AC 9 ms
23,460 KB
testcase_14 AC 12 ms
23,672 KB
testcase_15 AC 11 ms
23,484 KB
testcase_16 AC 15 ms
23,104 KB
testcase_17 AC 16 ms
23,688 KB
testcase_18 AC 9 ms
22,008 KB
testcase_19 AC 7 ms
22,552 KB
testcase_20 AC 5 ms
22,224 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 16 ms
24,616 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    string s, t;
    cin>>s>>t;
    int n=s.size(), m=t.size();
    int x[100010];
    x[n]=m;
    int r=m-1;
    for(int i=n-1; i>=0; i--){
        while(r>=0){
            if(t[r]==s[i]) break;
            r--;
        }
        x[i]=r;
        r--;
    }
    if(x[0]>=0){
        cout<<-1<<endl;
        return 0;
    }
    int nx[26][100010], nxt[26][100010];
    int tmp[26], tmp1[26], tmp2[26];
    for(int i=0; i<26; i++) tmp[i]=n;
    for(int i=n-1; i>=0; i--){
        for(int j=0; j<26; j++) nx[j][i]=tmp[j];
        tmp[s[i]-'a']=i;
    }
    for(int i=0; i<26; i++) tmp1[i]=tmp[i], tmp[i]=m;
    for(int i=m-1; i>=0; i--){
        for(int j=0; j<26; j++) nxt[j][i]=tmp[j];
        tmp[t[i]-'a']=i;
    }
    for(int i=0; i<26; i++) tmp2[i]=tmp[i];
    string ans;
    int p=-1, q=-1;
    while(1){
        bool myon=0;
        for(int i=0; i<26; i++){
            int p1, q1;
            if(p==-1) p1=tmp1[i];
            else p1=nx[i][p];
            if(q==-1) q1=tmp2[i];
            else q1=nxt[i][q];
            if(p1==n) continue;
            if(p1<n && q1==m){
                ans+=(char)('a'+i);
                myon=1; break;
            }else if(q1>=x[p1+1]){
                ans+=(char)('a'+i);
                p=p1, q=q1;
                break;
            }
        }
        if(myon) break;
    }
    cout<<ans<<endl;
    return 0;
}
0