結果

問題 No.1192 半部分列
ユーザー ShibuyapShibuyap
提出日時 2020-08-22 17:31:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,853 bytes
コンパイル時間 2,470 ms
コンパイル使用メモリ 197,188 KB
実行使用メモリ 14,456 KB
最終ジャッジ日時 2024-04-23 11:25:40
合計ジャッジ時間 3,756 ms
ジャッジサーバーID
(参考情報)
judge5 / 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 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 17 ms
14,204 KB
testcase_07 AC 13 ms
14,336 KB
testcase_08 AC 14 ms
14,420 KB
testcase_09 AC 16 ms
14,208 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 14 ms
14,456 KB
testcase_13 AC 6 ms
6,144 KB
testcase_14 AC 8 ms
8,960 KB
testcase_15 AC 10 ms
10,992 KB
testcase_16 AC 9 ms
9,208 KB
testcase_17 AC 11 ms
12,160 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 5 ms
5,632 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 13 ms
14,352 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:31:14: warning: '*need[0]' may be used uninitialized [-Wmaybe-uninitialized]
   31 |     if(need[0] >= 0){
      |        ~~~~~~^

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int need[n];
    rep(i,n)need[i] = -1;
    int now = m-1;
    drep(i,n){
        if(now == -1)break;
        while(now >= 0){
            if(t[now] == s[i]){
                need[i] = now;
                now--;
                break;
            }
            now--;
        }
    }

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

    int next[n][26];
    rep(i,n)rep(j,26)next[i][j] = n;
    drep(i,n-1){
        rep(j,26){
            next[i][j] = next[i+1][j];
        }
        int x = s[i+1] - 'a';
        next[i][x] = i+1;
    }
    int start[26];
    rep(j,26)start[j] = next[0][j];
    start[s[0]-'a'] = 0;

    string ans;
    now = 0;
    int ite = 0;
    int start_flag = 1;
    while(true){
        // cout << ite << endl;
        if(start_flag){
            start_flag = 0;
            rep(j,26){
                int nx = start[j];
                if(nx==n)continue;
                if(need[nx]<now){
                    char c = j + 'a';
                    ans += c;
                    if(now==m){
                        cout << ans << endl;
                        return 0;
                    }
                    while(now<m){
                        if(t[now] == c){
                            now++;
                            break;
                        }
                        now++;
                        if(now==m){
                            cout << ans << endl;
                            return 0;
                        }
                    }
                    ite = nx;
                    break;
                }
            }
        }else{
            rep(j,26){
                int nx = next[ite][j];
                if(nx==n)continue;
                if(need[nx]<now){
                    char c = j + 'a';
                    ans += c;
                    if(now==m){
                        cout << ans << endl;
                        return 0;
                    }
                    while(now<m){
                        if(t[now] == c){
                            now++;
                            break;
                        }
                        now++;
                        if(now==m){
                            cout << ans << endl;
                            return 0;
                        }
                    }
                    ite = nx;
                    break;
                }
            }
        }
    }

    return 0;
}


0