結果
問題 |
No.2759 Take Pictures, Elements?
|
ユーザー |
|
提出日時 | 2024-05-17 21:49:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 705 bytes |
コンパイル時間 | 2,112 ms |
コンパイル使用メモリ | 205,896 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 13:17:08 |
合計ジャッジ時間 | 3,022 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin >> N >> Q; map<int,vector<int>> rev; for(int i=0; i<N; i++){ int a; cin >> a; rev[a].push_back(i); } int inf = 1e9; vector<int> dp(N,inf); dp.at(0) = 0; while(Q--){ int b; cin >> b; vector<int> &ap = rev[b],next = dp; for(int i=1; i<N; i++) next.at(i) = min(next.at(i),next.at(i-1)+1); for(int i=N-2; i>=0; i--) next.at(i) = min(next.at(i),next.at(i+1)+1); dp.assign(N,inf); for(auto a : ap) dp.at(a) = next.at(a); } cout << *min_element(dp.begin(),dp.end()) << endl; }