結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-23 18:14:09 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 3,000 ms |
| コード長 | 1,928 bytes |
| コンパイル時間 | 12,349 ms |
| コンパイル使用メモリ | 386,504 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-12-22 05:28:59 |
| 合計ジャッジ時間 | 14,173 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
use std::{collections::BinaryHeap, cmp::Reverse};
const DX: [isize; 4] = [-1, 1, 0, 0];
const DY: [isize; 4] = [0, 0, -1, 1];
fn main() {
let mut hwyx = String::new();
std::io::stdin().read_line(&mut hwyx).ok();
let hwyx: Vec<usize> = hwyx.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let h = hwyx[0];
let w = hwyx[1];
let x = hwyx[2]-1;
let y = hwyx[3]-1;
let grid = (0..h).map(|_| {
let mut temp = String::new();
std::io::stdin().read_line(&mut temp).ok();
let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
temp
})
.collect::<Vec<Vec<usize>>>();
let mut checked = vec![vec![false; w]; h];
checked[x][y] = true;
let mut frontier = BinaryHeap::new();
let mut player_attack = grid[x][y];
for dir in 0..4 {
let nx = x as isize + DX[dir];
let ny = y as isize + DY[dir];
if nx >= 0 && ny >= 0 && nx < h as isize && ny < w as isize {
let nx = nx as usize;
let ny = ny as usize;
if checked[nx][ny] { continue; }
checked[nx][ny] = true;
frontier.push((Reverse(grid[nx][ny]), (nx, ny)));
}
}
while let Some((Reverse(attack), (cx, cy))) = frontier.pop() {
if attack >= player_attack {
println!("No");
return;
}
player_attack += attack;
for dir in 0..4 {
let nx = cx as isize + DX[dir];
let ny = cy as isize + DY[dir];
if nx >= 0 && ny >= 0 && nx < h as isize && ny < w as isize {
let nx = nx as usize;
let ny = ny as usize;
if checked[nx][ny] { continue; }
checked[nx][ny] = true;
frontier.push((Reverse(grid[nx][ny]), (nx, ny)));
}
}
}
println!("Yes");
}