結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー akakimidoriakakimidori
提出日時 2022-05-20 22:03:35
言語 Rust
(1.77.0)
結果
AC  
実行時間 69 ms / 3,000 ms
コード長 2,914 bytes
コンパイル時間 3,686 ms
コンパイル使用メモリ 177,936 KB
実行使用メモリ 8,708 KB
最終ジャッジ日時 2023-10-20 12:43:45
合計ジャッジ時間 5,501 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 32 ms
5,140 KB
testcase_08 AC 18 ms
6,676 KB
testcase_09 AC 44 ms
6,732 KB
testcase_10 AC 40 ms
6,732 KB
testcase_11 AC 46 ms
6,700 KB
testcase_12 AC 42 ms
5,916 KB
testcase_13 AC 36 ms
4,620 KB
testcase_14 AC 38 ms
8,708 KB
testcase_15 AC 38 ms
8,708 KB
testcase_16 AC 9 ms
4,876 KB
testcase_17 AC 69 ms
6,776 KB
testcase_18 AC 9 ms
4,876 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 53 ms
5,920 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 20 ms
4,620 KB
testcase_25 AC 31 ms
5,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn run() {
    input! {
        h: usize,
        w: usize,
        x: usize1,
        y: usize1,
        a: [[i64; w]; h],
    }
    let neighbor = |x: usize, y: usize| {
        [(0, 1), (1, 0), (!0, 0), (0, !0)]
            .iter()
            .map(move |p| (p.0 + x, p.1 + y))
            .filter(|p| p.0 < h && p.1 < w)
    };
    let mut used = vec![vec![false; w]; h];
    used[x][y] = true;
    let mut sum = a[x][y];
    let mut h = std::collections::BinaryHeap::new();
    for (x, y) in neighbor(x, y) {
        used[x][y] = true;
        h.push((-a[x][y], x, y));
    }
    while let Some((v, x, y)) = h.pop() {
        let v = -v;
        if v >= sum {
            println!("No");
            return;
        }
        sum += v;
        for (x, y) in neighbor(x, y) {
            if !used[x][y] {
                used[x][y] = true;
                h.push((-a[x][y], x, y));
            }
        }
    }
    println!("Yes");
}

fn main() {
    run();
}

// ---------- 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 ----------
// ---------- 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 ----------
0