結果

問題 No.2826 Earthwork
ユーザー akakimidoriakakimidori
提出日時 2024-07-26 22:36:19
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 5,601 bytes
コンパイル時間 15,952 ms
コンパイル使用メモリ 393,288 KB
実行使用メモリ 113,364 KB
最終ジャッジ日時 2024-07-26 22:36:47
合計ジャッジ時間 24,031 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 74 ms
25,600 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 149 ms
58,048 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 20 ms
6,940 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 185 ms
74,544 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 26 ms
7,040 KB
testcase_40 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
 --> src/main.rs:3:5
  |
3 | use std::io::Write;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `src`
  --> src/main.rs:22:13
   |
22 |         let src = n * n;
   |             ^^^ help: if this is intentional, prefix it with an underscore: `_src`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> src/main.rs:79:13
   |
79 |         let mut dp = dp.iter().cloned().take(n * n).collect::<Vec<_>>();
   |             ----^^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` 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>;
  |      ^^^^^

ソースコード

diff #

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];
        let mut dp = vec![std::i64::MAX / 2; n * n];
        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 {
                        dp[v].chmin(h);
                    } else {
                    }
                } else if *s == b'+' {
                    if cond {
                    } else {
                        dp[v].chmin(-h);
                    }
                } else if *s == b'=' {
                    if cond {
                        dp[v].chmin(h);
                    } else {
                        dp[v].chmin(-h);
                    }
                } else {
                }
            }
        }
        let mut pq = std::collections::BinaryHeap::new();
        for i in 0..n {
            if dp[i] != std::i64::MAX / 2 {
                pq.push((-dp[i], i));
            }
        }
        while let Some((d, v)) = pq.pop() {
            let d = -d;
            if d > dp[v] {
                continue;
            }
            for &(u, w) in g[v].iter() {
                if dp[u].chmin(d + w) {
                    pq.push((-dp[u], 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 ----------
0