結果

問題 No.1192 半部分列
ユーザー chocoruskchocorusk
提出日時 2020-08-22 15:13:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,900 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 127,516 KB
実行使用メモリ 24,576 KB
最終ジャッジ日時 2024-04-23 09:36:20
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 14 ms
24,568 KB
testcase_09 AC 13 ms
23,936 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 14 ms
24,360 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 10 ms
16,384 KB
testcase_16 AC 8 ms
13,056 KB
testcase_17 AC 10 ms
16,640 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 5 ms
7,680 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 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;
    }
    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