結果

問題 No.2855 Move on Grid
ユーザー 👑 KA37RIKA37RI
提出日時 2024-08-25 15:56:55
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 12,606 ms
コンパイル使用メモリ 402,460 KB
実行使用メモリ 184,360 KB
最終ジャッジ日時 2024-08-25 15:57:35
合計ジャッジ時間 32,611 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::collections::BinaryHeap;

use proconio::input;

fn main() {
  input! {
    n: usize,
    m: usize,
    k: usize,
    a: [[u64; m]; n],
  }

  let e9 = 10u64.pow(9);

  if k >= n + m - 1 {
    println!("{}", e9);
    return;
  }

  let mut visited = vec![vec![vec![false; k + 1]; m]; n];
  let mut p_queue = BinaryHeap::new();
  p_queue.push((a[0][0], 0, 0, 0));

  if k > 0 && a[0][0] < e9 {
    p_queue.push((e9, 0, 0, 1));
  }

  while let Some((cs, ci, cj, ck)) = p_queue.pop() {
    if visited[ci][cj][ck] {
      continue;
    } else if (n - ci) + (m - ci) - 1 <= k - ck {
      println!("{}", cs);
      return;
    }
    visited[ci][cj][ck] = true;

    for (di, dj) in [(-1, 0), (1, 0), (0, -1), (0, 1)] {
      let ni = ci as isize + di;
      let nj = cj as isize + dj;
      if ni < 0 || n <= ni as usize || nj < 0 || m <= nj as usize {
        continue;
      }
      let ni = ni as usize;
      let nj = nj as usize;

      if k > ck && a[ni][nj] < e9 {
        p_queue.push((cs, ni, nj, ck + 1));
      }
      p_queue.push((cs.min(a[ni][nj]), ni, nj, ck));
    }
  }

}
0