結果

問題 No.3427 Erasing a Subsequence
コンテスト
ユーザー GOTKAKO
提出日時 2026-01-11 15:13:24
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 1,021 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,371 ms
コンパイル使用メモリ 225,204 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-01-11 15:13:31
合計ジャッジ時間 5,871 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<int> S(N),T(M);
    for(auto &s : S) cin >> s;
    for(auto &t : T) cin >> t;

    vector<vector<bool>> OK(N+1,vector<bool>(M+1));
    OK.at(N).at(M) = true;
    for(int i=N-1; i>=0; i--){
        OK.at(i) = OK.at(i+1);
        for(int k=0; k<M; k++) if(OK.at(i+1).at(k+1) && S.at(i) == T.at(k)) OK.at(i).at(k) = true;
    }
    
    vector<int> best(N-M,1001001),now(N-M);
    auto dfs = [&](auto dfs,int pos,int p) -> void {
        if(pos == N){
            best = min(best,now);
            return;
        }
        if(OK.at(pos).at(p) == false) return;
        if(p == M) now.at(pos-p) = S.at(pos),dfs(dfs,pos+1,p);
        else{
            if(S.at(pos) == T.at(p)) dfs(dfs,pos+1,p+1);
            if(pos-p < N-M) now.at(pos-p) = S.at(pos),dfs(dfs,pos+1,p);
        } 
    };
    dfs(dfs,0,0);

    for(auto &a : best) cout << a << " "; cout << endl;   
}
0