結果
問題 |
No.2759 Take Pictures, Elements?
|
ユーザー |
|
提出日時 | 2024-05-18 01:22:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 991 bytes |
コンパイル時間 | 1,047 ms |
コンパイル使用メモリ | 117,712 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 13:19:38 |
合計ジャッジ時間 | 1,814 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <ranges> constexpr int64_t INF = (1LL << 61) - 1; template <class T, class U> constexpr inline bool chmin(T& a, const U& b) noexcept { if(a>b){ a=b; return 1; } return 0; } int main() { std::cin.tie(nullptr) -> sync_with_stdio(false); int n, q; std::cin >> n >> q; std::vector<int> a(n), b(q); for(auto &el: a) { std::cin >> el; } for(auto &el: b) { std::cin >> el; } std::vector<int64_t> dp(n, INF); dp[0] = 0; for(const auto e: b) { for(const auto i: std::views::iota(0, n - 1)) { chmin(dp[i + 1], dp[i] + 1); } for(const auto i: std::views::iota(1, n) | std::views::reverse) { chmin(dp[i - 1], dp[i] + 1); } for(const auto i: std::views::iota(0, n)) { if(a[i] != e) { dp[i] = INF; } } } std::cout << *std::ranges::min_element(dp) << '\n'; }