結果

問題 No.1283 Extra Fee
ユーザー fukafukatanifukafukatani
提出日時 2020-11-06 21:54:17
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,874 bytes
コンパイル時間 3,396 ms
コンパイル使用メモリ 155,608 KB
実行使用メモリ 21,388 KB
最終ジャッジ日時 2023-09-29 18:40:21
合計ジャッジ時間 6,332 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 38 ms
7,104 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 148 ms
21,172 KB
testcase_24 AC 153 ms
21,192 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 40 ms
7,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:22:9
   |
22 |     for i in 0..m {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut cost_dict = HashMap::new();
    for i in 0..m {
        let v = read_vec::<i64>();
        let (h, w, c) = (v[0] as usize - 1, v[1] as usize - 1, v[2]);
        cost_dict.insert((h, w), c);
    }

    let mut dp = vec![vec![vec![std::i64::MAX; n]; n]; 2];
    dp[0][0][0] = 0;
    dp[1][0][0] = 0;
    for h in 0..n {
        for w in 0..n {
            let cur_cost;
            if cost_dict.contains_key(&(h, w)) {
                cur_cost = cost_dict[&(h, w)];
            } else {
                cur_cost = 0;
            }
            for k in 0..2 {
                if h > 0 {
                    dp[k][h][w] = min(dp[k][h][w], dp[k][h - 1][w] + 1 + cur_cost);
                }
                if w > 0 {
                    dp[k][h][w] = min(dp[k][h][w], dp[k][h][w - 1] + 1 + cur_cost);
                }
            }
            if h > 0 {
                dp[1][h][w] = min(dp[1][h][w], dp[0][h - 1][w] + 1);
            }
            if w > 0 {
                dp[1][h][w] = min(dp[1][h][w], dp[0][h][w - 1] + 1);
            }
        }
    }
    println!("{}", dp[1][n - 1][n - 1]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0