結果
| 問題 |
No.2759 Take Pictures, Elements?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-17 22:14:54 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,756 bytes |
| コンパイル時間 | 13,538 ms |
| コンパイル使用メモリ | 399,592 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-20 13:18:15 |
| 合計ジャッジ時間 | 12,447 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 RE * 2 |
| other | WA * 11 RE * 10 |
ソースコード
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
use proconio::marker::{Bytes, Chars, Isize1, Usize1};
use proconio::{fastout, input, input_interactive};
#[fastout]
fn main() {
input! {
N: usize,
Q: usize,
A: [i64; N],
mut B: [i64; Q],
}
B.dedup();
let B = B;
let mut dp = vec![usize::MAX; N];
dp[0] = 0;
let pos_per_b = {
let mut ret = vec![vec![]; N];
for i in 0..N {
ret[A[i] as usize].push(i);
}
ret
};
for b in B {
let mut new_dp = vec![usize::MAX; N];
for from in 0..N {
if dp[from] == usize::MAX {
continue;
}
for to in pos_per_b[b as usize].iter() {
chmin!(new_dp[*to], dp[from] + to.abs_diff(from));
}
}
}
let ans = dp.iter().min().unwrap();
println!("{}", ans);
}
#[macro_export]
macro_rules! mat {
($($e:expr),*) => { vec![$($e),*] };
($($e:expr,)*) => { vec![$($e),*] };
($e:expr; $d:expr) => { vec![$e; $d] };
($e:expr; $d:expr $(; $ds:expr)+) => { vec![mat![$e $(; $ds)*]; $d] };
}
#[macro_export]
macro_rules! chmin {
($a:expr, $b:expr) => {
if $a > $b {
$a = $b;
true
} else {
false
}
};
}
#[macro_export]
macro_rules! chmax {
($a:expr, $b:expr) => {
if $a < $b {
$a = $b;
true
} else {
false
}
};
}
/// https://maguro.dev/debug-macro/
#[macro_export]
macro_rules! debug {
($($a:expr),* $(,)*) => {
#[cfg(debug_assertions)]
eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
};
}