結果

問題 No.2855 Move on Grid
ユーザー naut3naut3
提出日時 2024-08-25 14:37:10
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,817 bytes
コンパイル時間 13,606 ms
コンパイル使用メモリ 401,944 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-25 14:37:31
合計ジャッジ時間 13,692 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 5 ms
6,816 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
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 AC 20 ms
6,940 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case, unused_must_use, unused_imports)]
use std::io::{self, prelude::*};

fn main() {
    let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout());
    let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock()));
    macro_rules! input {
        ($t: ty, $n: expr) => {
            (0..$n).map(|_| input!($t)).collect::<Vec<_>>()
        };
        ($t: ty) => {
            stdin.next().unwrap().parse::<$t>().unwrap()
        };
    }

    let N = input!(usize);
    let M = input!(usize);
    let K = input!(usize);
    let A = {
        let mut a = vec![];

        for _ in 0..N {
            let r = input!(u32, M);
            a.push(r);
        }

        a
    };

    if N + M - 2 <= K {
        writeln!(buffer, "1000000000");
        return;
    }

    // 頑張って K 個保持して dp で云々みたいに考えていたが、二分探索でいける説
    let mut ok = 0;
    let mut ng = 1_000_000_001;

    while ng - ok > 1 {
        let m = (ok + ng) / 2;

        let mut dp = vec![vec![u16::MAX; M]; N];
        dp[0][0] = if A[0][0] < m { 1 } else { 0 };

        for y in 0..N {
            for x in 0..M {
                if x == 0 && y == 0 {
                    continue;
                }

                if x > 0 {
                    dp[y][x] =
                        std::cmp::min(dp[y][x], dp[y][x - 1] + if A[y][x] < m { 1 } else { 0 });
                }

                if y > 0 {
                    dp[y][x] =
                        std::cmp::min(dp[y][x], dp[y - 1][x] + if A[y][x] < m { 1 } else { 0 });
                }
            }
        }

        if dp[N - 1][M - 1] <= K as u16 {
            ok = m;
        } else {
            ng = m;
        }
    }

    writeln!(buffer, "{}", ok);
}
0