結果
問題 | No.2321 Continuous Flip |
ユーザー | akakimidori |
提出日時 | 2023-05-26 21:47:44 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 258 ms / 2,000 ms |
コード長 | 2,908 bytes |
コンパイル時間 | 12,567 ms |
コンパイル使用メモリ | 401,548 KB |
実行使用メモリ | 38,816 KB |
最終ジャッジ日時 | 2024-06-07 06:24:47 |
合計ジャッジ時間 | 21,362 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 241 ms
36,792 KB |
testcase_05 | AC | 230 ms
36,656 KB |
testcase_06 | AC | 230 ms
36,660 KB |
testcase_07 | AC | 232 ms
36,780 KB |
testcase_08 | AC | 225 ms
36,680 KB |
testcase_09 | AC | 223 ms
36,640 KB |
testcase_10 | AC | 239 ms
36,648 KB |
testcase_11 | AC | 242 ms
36,524 KB |
testcase_12 | AC | 238 ms
36,652 KB |
testcase_13 | AC | 230 ms
36,792 KB |
testcase_14 | AC | 243 ms
36,652 KB |
testcase_15 | AC | 258 ms
36,908 KB |
testcase_16 | AC | 226 ms
36,520 KB |
testcase_17 | AC | 244 ms
36,660 KB |
testcase_18 | AC | 226 ms
36,528 KB |
testcase_19 | AC | 241 ms
36,776 KB |
testcase_20 | AC | 253 ms
36,664 KB |
testcase_21 | AC | 243 ms
36,648 KB |
testcase_22 | AC | 240 ms
36,792 KB |
testcase_23 | AC | 247 ms
36,528 KB |
testcase_24 | AC | 62 ms
31,356 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 61 ms
35,612 KB |
testcase_27 | AC | 71 ms
38,076 KB |
testcase_28 | AC | 160 ms
38,696 KB |
testcase_29 | AC | 160 ms
38,816 KB |
testcase_30 | AC | 166 ms
38,816 KB |
testcase_31 | AC | 164 ms
38,688 KB |
testcase_32 | AC | 153 ms
38,700 KB |
testcase_33 | AC | 164 ms
38,684 KB |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> src/main.rs:1:5 | 1 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: type alias `Map` is never used --> src/main.rs:4:6 | 4 | type Map<K, V> = BTreeMap<K, V>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Set` is never used --> src/main.rs:5:6 | 5 | type Set<T> = BTreeSet<T>; | ^^^ warning: type alias `Deque` is never used --> src/main.rs:6:6 | 6 | type Deque<T> = VecDeque<T>; | ^^^^^
ソースコード
use std::io::Write; use std::collections::*; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; type Deque<T> = VecDeque<T>; fn main() { input! { n: usize, m: usize, c: i64, a: [i64; n], p: [(usize1, usize); m], } let mut g = vec![vec![]; n + 1]; for (l, r) in p { g[l].push((r, c)); g[r].push((l, c)); } for i in 1..=n { g[i].push((i - 1, a[i - 1])); g[i - 1].push((i, a[i - 1])); } let mut h = std::collections::BinaryHeap::new(); let mut dp = vec![std::i64::MAX / 2; n + 1]; dp[0] = 0; h.push((0, 0)); while let Some((d, v)) = h.pop() { let d = -d; if d > dp[v] { continue; } for &(u, w) in g[v].iter() { if dp[u].chmin(d + w) { h.push((-dp[u], u)); } } } let ans = a.iter().sum::<i64>() - dp[n]; println!("{}", ans); } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- // ---------- begin chmin, chmax ---------- pub trait ChangeMinMax { fn chmin(&mut self, x: Self) -> bool; fn chmax(&mut self, x: Self) -> bool; } impl<T: PartialOrd> ChangeMinMax for T { fn chmin(&mut self, x: Self) -> bool { *self > x && { *self = x; true } } fn chmax(&mut self, x: Self) -> bool { *self < x && { *self = x; true } } } // ---------- end chmin, chmax ----------