結果
問題 | No.2826 Earthwork |
ユーザー | akakimidori |
提出日時 | 2024-07-26 22:16:34 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,787 bytes |
コンパイル時間 | 13,291 ms |
コンパイル使用メモリ | 391,052 KB |
実行使用メモリ | 118,232 KB |
最終ジャッジ日時 | 2024-07-26 22:17:00 |
合計ジャッジ時間 | 22,923 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 68 ms
5,376 KB |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> src/main.rs:3:5 | 3 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: type alias `Map` is never used --> src/main.rs:5:6 | 5 | type Map<K, V> = BTreeMap<K, V>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Set` is never used --> src/main.rs:6:6 | 6 | type Set<T> = BTreeSet<T>; | ^^^ warning: type alias `Deque` is never used --> src/main.rs:7:6 | 7 | type Deque<T> = VecDeque<T>; | ^^^^^
ソースコード
use std::collections::*; use std::io::Write; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; type Deque<T> = VecDeque<T>; fn main() { input! { n: usize, h: [[i64; n]; n], s: [bytes; n], a: [[i64; n]; n - 1], b: [[i64; n - 1]; n], q: usize, ask: [(usize1, usize1, i64); q], } let mut ans = vec![std::i64::MIN; n * n]; for sign in 0..2 { let pos = |x: usize, y: usize| x * n + y; let src = n * n; let mut g = vec![vec![]; n * n + 1]; for (i, s) in s.iter().enumerate() { for (j, s) in s.iter().enumerate() { let cond = (i + j) & 1 == sign; let v = pos(i, j); if i + 1 < n { let d = a[i][j] * (h[i][j] + h[i + 1][j]).abs(); let u = pos(i + 1, j); g[u].push((v, d)); g[v].push((u, d)); } if j + 1 < n { let d = b[i][j] * (h[i][j] + h[i][j + 1]).abs(); let u = pos(i, j + 1); g[u].push((v, d)); g[v].push((u, d)); } let h = h[i][j]; if *s == b'-' { if cond { g[src].push((v, h)); } else { g[v].push((src, h)); } } else if *s == b'+' { if cond { g[v].push((src, -h)); } else { g[src].push((v, -h)); } } else if *s == b'=' { if cond { g[src].push((v, h)); g[v].push((src, -h)); } else { g[src].push((v, -h)); g[v].push((src, h)); } } else { } } } let mut elem = vec![false; n * n + 1]; elem[src] = true; let mut dp = vec![std::i64::MAX / 2; n * n + 1]; dp[src] = 0; let mut deq = std::collections::VecDeque::new(); deq.push_back(src); while let Some(v) = deq.pop_front() { let d = dp[v]; elem[v] = false; for &(u, w) in g[v].iter() { if dp[u].chmin(d + w) && !elem[u] { elem[u] = true; deq.push_back(u); } } } let mut dp = dp.iter().cloned().take(n * n).collect::<Vec<_>>(); for i in 0..n { for j in 0..n { if (i + j) & 1 != sign { dp[i * n + j] *= -1; } } } for i in 0..n { for j in 0..n { if i + 1 < n { assert!((dp[pos(i, j)] + dp[pos(i + 1, j)]).abs() <= a[i][j] * (h[i][j] + h[i + 1][j]).abs()); } if j + 1 < n { assert!((dp[pos(i, j)] + dp[pos(i, j + 1)]).abs() <= b[i][j] * (h[i][j] + h[i][j + 1]).abs()); } if s[i][j] == b'-' { assert!(dp[pos(i, j)] <= h[i][j]); } else if s[i][j] == b'+' { assert!(dp[pos(i, j)] >= h[i][j]); } else if s[i][j] == b'=' { assert!(dp[pos(i, j)] == h[i][j]); } else { } } } for (i, dp) in dp.iter().enumerate().take(n * n) { if (i / n + i % n) % 2 == sign { ans[i] = *dp; } } } for (a, b, c) in ask { let ans = if ans[a * n + b] >= c {"Yes"} else {"No"}; 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 ----------