結果
| 問題 | No.3427 Erasing a Subsequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-11 15:19:46 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,508 bytes |
| 記録 | |
| コンパイル時間 | 2,338 ms |
| コンパイル使用メモリ | 225,672 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-11 15:19:49 |
| 合計ジャッジ時間 | 2,970 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
#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,bool win) -> bool {
if(pos == N){
best = now;
return true;
}
if(OK.at(pos).at(p) == false) return false;
if(p == M){
if(!win && S.at(pos) > best.at(pos-p)) return false;
if(S.at(pos) < best.at(pos-p)) win = true;
now.at(pos-p) = S.at(pos);
return dfs(dfs,pos+1,p,win);
}
else{
bool ret = false;
if(S.at(pos) == T.at(p)){
if(dfs(dfs,pos+1,p+1,win)) ret = true,win = false;
}
if(pos-p < N-M){
if(!win && S.at(pos) > best.at(pos-p)) return ret;
if(S.at(pos) < best.at(pos-p)) win = true;
now.at(pos-p) = S.at(pos);
ret |= dfs(dfs,pos+1,p,win);
}
return ret;
}
};
dfs(dfs,0,0,true);
for(auto &a : best) cout << a << " "; cout << endl;
}