結果
問題 |
No.20 砂漠のオアシス
|
ユーザー |
|
提出日時 | 2019-12-11 00:21:44 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 12 ms / 5,000 ms |
コード長 | 2,147 bytes |
コンパイル時間 | 14,590 ms |
コンパイル使用メモリ | 404,696 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-24 06:23:02 |
合計ジャッジ時間 | 15,868 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
use std::io::Read; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let v: i32 = itr.next().unwrap().parse().unwrap(); let mut ox: usize = itr.next().unwrap().parse().unwrap(); let mut oy: usize = itr.next().unwrap().parse().unwrap(); let field: Vec<Vec<i32>> = (0..n) .map(|_| { (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect() }) .collect(); const INF: i32 = 40000; let mut q = std::collections::BinaryHeap::new(); let mut first: Vec<Vec<i32>> = vec![vec![-INF; n]; n]; let mut second: Vec<Vec<i32>> = vec![vec![-INF; n]; n]; q.push((v, 0)); first[0][0] = v; while let Some((life, pos)) = q.pop() { let y = pos / 1000; let x = pos % 1000; for (dy, dx) in vec![(-1, 0), (0, -1), (1, 0), (0, 1)] { let ny = (y as isize + dy) as usize; let nx = (x as isize + dx) as usize; if ny < n && nx < n && first[ny][nx] == -INF { first[ny][nx] = life - field[ny][nx]; q.push((first[ny][nx], ny * 1000 + nx)); } } } if ox != 0 || oy != 0 { oy -= 1; ox -= 1; second[oy][ox] = first[oy][ox] * 2; q.push((second[oy][ox], oy * 1000 + ox)); while let Some((life, pos)) = q.pop() { let y = pos / 1000; let x = pos % 1000; for (dy, dx) in vec![(-1, 0), (0, -1), (1, 0), (0, 1)] { let ny = (y as isize + dy) as usize; let nx = (x as isize + dx) as usize; if ny < n && nx < n && second[ny][nx] == -INF { second[ny][nx] = life - field[ny][nx]; q.push((second[ny][nx], ny * 1000 + nx)); } } } } println!( "{}", if first[n - 1][n - 1] > 0 || second[n - 1][n - 1] > 0 { "YES" } else { "NO" } ); }