結果
問題 |
No.2759 Take Pictures, Elements?
|
ユーザー |
|
提出日時 | 2024-05-17 23:04:57 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 867 bytes |
コンパイル時間 | 12,443 ms |
コンパイル使用メモリ | 381,208 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 13:19:21 |
合計ジャッジ時間 | 11,610 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
use proconio::input; const INF: usize = 10_usize.pow(6); fn main() { input! { (n, q): (usize, usize), aa: [usize; n], bb: [usize; q], } let mut dp = vec![INF; n]; dp[0] = 0; for &b in &bb { let mut next_dp = vec![INF; n]; let mut to_right = INF; for (i, &a) in aa.iter().enumerate() { to_right = to_right.min(dp[i] + n - 1 - i); if a == b { next_dp[i] = next_dp[i].min(to_right - (n - 1 - i)); } } let mut to_left = INF; for (i, &a) in aa.iter().enumerate().rev() { to_left = to_left.min(dp[i] + i); if a == b { next_dp[i] = next_dp[i].min(to_left - i); } } dp = next_dp; } let ans = *dp.iter().min().unwrap(); println!("{}", ans); }