結果

問題 No.1192 半部分列
ユーザー chocoruskchocorusk
提出日時 2020-08-22 15:16:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,913 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 127,096 KB
実行使用メモリ 24,328 KB
最終ジャッジ日時 2023-08-05 12:28:18
合計ジャッジ時間 2,506 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
21,892 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 6 ms
21,796 KB
testcase_03 AC 5 ms
21,996 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
21,868 KB
testcase_06 AC 28 ms
24,292 KB
testcase_07 AC 17 ms
24,216 KB
testcase_08 AC 16 ms
24,176 KB
testcase_09 AC 16 ms
24,008 KB
testcase_10 AC 6 ms
21,960 KB
testcase_11 AC 5 ms
21,832 KB
testcase_12 AC 16 ms
24,128 KB
testcase_13 AC 11 ms
23,124 KB
testcase_14 AC 12 ms
23,288 KB
testcase_15 AC 13 ms
23,220 KB
testcase_16 AC 11 ms
22,812 KB
testcase_17 AC 12 ms
23,084 KB
testcase_18 AC 5 ms
21,940 KB
testcase_19 AC 7 ms
22,232 KB
testcase_20 AC 5 ms
21,960 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 15 ms
24,328 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,380 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