結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-10 10:48:10 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 3,000 ms |
| コード長 | 1,869 bytes |
| コンパイル時間 | 12,482 ms |
| コンパイル使用メモリ | 388,200 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-11-26 12:13:52 |
| 合計ジャッジ時間 | 14,583 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
use std::{collections::BinaryHeap, cmp::Reverse};
fn main() {
println!("{}", if solve() { "Yes" } else { "No" });
}
fn solve() -> bool {
let (h, w, y, x) = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse::<usize>().unwrap(),
iter.next().unwrap().parse::<usize>().unwrap(),
iter.next().unwrap().parse::<usize>().unwrap() - 1,
iter.next().unwrap().parse::<usize>().unwrap() - 1,
)
};
let mut aaa = vec![];
for _ in 0..h {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
aaa.push(
line.split_whitespace()
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>(),
);
}
let mut player_power = aaa[y][x];
let mut visited = vec![vec![false; w]; h];
visited[y][x] = true;
let mut heap = BinaryHeap::from(vec![(Reverse(0), (y, x))]);
while let Some((enemy_power, (y, x))) = heap.pop() {
if player_power <= enemy_power.0 {
return false;
}
player_power += enemy_power.0;
if y > 0 && !visited[y - 1][x] {
heap.push((Reverse(aaa[y - 1][x]), (y - 1, x)));
visited[y - 1][x] = true;
}
if y < h - 1 && !visited[y + 1][x] {
heap.push((Reverse(aaa[y + 1][x]), (y + 1, x)));
visited[y + 1][x] = true;
}
if x > 0 && !visited[y][x - 1] {
heap.push((Reverse(aaa[y][x - 1]), (y, x - 1)));
visited[y][x - 1] = true;
}
if x < w - 1 && !visited[y][x + 1] {
heap.push((Reverse(aaa[y][x + 1]), (y, x + 1)));
visited[y][x + 1] = true;
}
}
true
}