結果

問題 No.2826 Earthwork
ユーザー akakimidoriakakimidori
提出日時 2024-07-27 00:07:55
言語 Rust
(1.77.0 + proconio)
結果
RE  
実行時間 -
コード長 5,664 bytes
コンパイル時間 13,638 ms
コンパイル使用メモリ 401,184 KB
実行使用メモリ 184,592 KB
最終ジャッジ日時 2024-07-27 00:08:41
合計ジャッジ時間 37,293 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 27 ms
6,816 KB
testcase_02 AC 1,027 ms
180,012 KB
testcase_03 AC 99 ms
19,200 KB
testcase_04 AC 781 ms
154,468 KB
testcase_05 RE -
testcase_06 AC 517 ms
97,180 KB
testcase_07 AC 656 ms
123,084 KB
testcase_08 AC 1,027 ms
180,788 KB
testcase_09 AC 1,098 ms
180,980 KB
testcase_10 AC 1,014 ms
184,592 KB
testcase_11 RE -
testcase_12 AC 28 ms
6,940 KB
testcase_13 AC 307 ms
58,796 KB
testcase_14 AC 1,225 ms
182,268 KB
testcase_15 AC 266 ms
46,296 KB
testcase_16 RE -
testcase_17 AC 157 ms
28,672 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 787 ms
150,548 KB
testcase_21 RE -
testcase_22 AC 704 ms
119,940 KB
testcase_23 AC 578 ms
120,104 KB
testcase_24 AC 1,056 ms
181,640 KB
testcase_25 RE -
testcase_26 AC 633 ms
118,452 KB
testcase_27 RE -
testcase_28 AC 1,188 ms
182,008 KB
testcase_29 RE -
testcase_30 AC 41 ms
8,476 KB
testcase_31 AC 74 ms
14,720 KB
testcase_32 AC 22 ms
6,940 KB
testcase_33 AC 621 ms
98,864 KB
testcase_34 AC 1,001 ms
183,324 KB
testcase_35 AC 223 ms
44,504 KB
testcase_36 AC 1,108 ms
180,944 KB
testcase_37 AC 1,092 ms
182,744 KB
testcase_38 AC 522 ms
91,828 KB
testcase_39 RE -
testcase_40 AC 35 ms
7,424 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
 --> src/main.rs:2:5
  |
2 | use std::io::Write;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `src`
  --> src/main.rs:21:13
   |
21 |         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:78:13
   |
78 |         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:4:6
  |
4 | type Map<K, V> = BTreeMap<K, V>;
  |      ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
 --> src/main.rs:5:6
  |
5 | type Set<T> = BTreeSet<T>;
  |      ^^^

warning: type alias `Deque` is never used
 --> src/main.rs:6:6
  |
6 | 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: [[i128; n]; n],
        s: [bytes; n],
        a: [[i128; n]; n - 1],
        b: [[i128; n - 1]; n],
        q: usize,
        ask: [(usize1, usize1, i128); q],
    }
    let mut ans = vec![std::i128::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::i128::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 * n) {
            if dp[i] != std::i128::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) {
        	assert!(*dp < ((std::i64::MAX) as i128));
            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