結果

問題 No.2509 Beam Shateki
ユーザー 👑 KA37RIKA37RI
提出日時 2023-09-26 20:40:06
言語 Rust
(1.77.0)
結果
AC  
実行時間 984 ms / 2,000 ms
コード長 1,759 bytes
コンパイル時間 1,255 ms
コンパイル使用メモリ 180,172 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-16 23:30:00
合計ジャッジ時間 29,838 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 132 ms
4,348 KB
testcase_04 AC 131 ms
4,348 KB
testcase_05 AC 131 ms
4,348 KB
testcase_06 AC 134 ms
4,348 KB
testcase_07 AC 131 ms
4,348 KB
testcase_08 AC 131 ms
4,348 KB
testcase_09 AC 131 ms
4,348 KB
testcase_10 AC 131 ms
4,348 KB
testcase_11 AC 132 ms
4,348 KB
testcase_12 AC 131 ms
4,348 KB
testcase_13 AC 984 ms
4,348 KB
testcase_14 AC 982 ms
4,348 KB
testcase_15 AC 984 ms
4,348 KB
testcase_16 AC 978 ms
4,348 KB
testcase_17 AC 955 ms
4,348 KB
testcase_18 AC 982 ms
4,348 KB
testcase_19 AC 981 ms
4,348 KB
testcase_20 AC 983 ms
4,348 KB
testcase_21 AC 959 ms
4,348 KB
testcase_22 AC 956 ms
4,348 KB
testcase_23 AC 978 ms
4,348 KB
testcase_24 AC 982 ms
4,348 KB
testcase_25 AC 982 ms
4,348 KB
testcase_26 AC 956 ms
4,348 KB
testcase_27 AC 978 ms
4,348 KB
testcase_28 AC 980 ms
4,348 KB
testcase_29 AC 981 ms
4,348 KB
testcase_30 AC 977 ms
4,348 KB
testcase_31 AC 955 ms
4,348 KB
testcase_32 AC 979 ms
4,348 KB
testcase_33 AC 21 ms
4,348 KB
testcase_34 AC 245 ms
4,348 KB
testcase_35 AC 496 ms
4,348 KB
testcase_36 AC 73 ms
4,348 KB
testcase_37 AC 5 ms
4,348 KB
testcase_38 AC 132 ms
4,348 KB
testcase_39 AC 66 ms
4,348 KB
testcase_40 AC 296 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 102 ms
4,348 KB
testcase_43 AC 558 ms
4,348 KB
testcase_44 AC 691 ms
4,348 KB
testcase_45 AC 70 ms
4,348 KB
testcase_46 AC 111 ms
4,348 KB
testcase_47 AC 730 ms
4,348 KB
testcase_48 AC 251 ms
4,348 KB
testcase_49 AC 279 ms
4,348 KB
testcase_50 AC 389 ms
4,348 KB
testcase_51 AC 13 ms
4,348 KB
testcase_52 AC 219 ms
4,348 KB
testcase_53 AC 1 ms
4,348 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 1 ms
4,348 KB
testcase_57 AC 1 ms
4,348 KB
testcase_58 AC 1 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 1 ms
4,348 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 AC 1 ms
4,348 KB
testcase_63 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn solve() -> i64 {
  let hw: Vec<usize> = input().split_whitespace().map(|x| x.parse().unwrap()).collect();
  let h = hw[0];
  let w = hw[1];
  let a: Vec<Vec<i64>> = (0..h).map(|_| {
    input().split_whitespace().map(|x| x.parse().unwrap()).collect()
  }).collect();
  let mut ans = 0;
  let mut outer = vec![(0, 0), (h + 1, 0), (0, w + 1), (h + 1, w + 1)];
  for i in 1..=h {
    outer.push((i, 0));
    outer.push((i, w + 1));
  }
  for j in 1..=w {
    outer.push((0, j));
  }
  let outer = outer;
  let dir = [(-1, 0), (1, 0), (0, 1), (0, -1), (-1, 1), (1, 1), (-1, -1), (1, -1)];
  for &(ox1, oy1) in outer.iter() {
    for &(dx1, dy1) in dir.iter() {
      let mut score1 = 0;
      let mut px = ox1;
      let mut py = oy1;
      let mut placed = vec![vec![true; w]; h];
      loop {
        px = px.saturating_add_signed(dx1).min(h + 1);
        py = py.saturating_add_signed(dy1).min(w + 1);
        if px == 0 || px == h + 1 || py == 0 || py == w + 1 { break; }
        score1 += a[px-1][py-1];
        placed[px-1][py-1] = false;
      }
      for &(ox2, oy2) in outer.iter() {
        for &(dx2, dy2) in dir.iter() {
          let mut score2 = score1;
          px = ox2;
          py = oy2;
          loop {
            px = px.saturating_add_signed(dx2).min(h + 1);
            py = py.saturating_add_signed(dy2).min(w + 1);
            if px == 0 || px == h + 1 || py == 0 || py == w + 1 { break; }
            if placed[px-1][py-1] { score2 += a[px-1][py-1]; }
          }
          ans = ans.max(score2);
        }
      }
    }
  }
  return ans;
}

fn input() -> String {
  let mut buffer = String::new();
  std::io::stdin().read_line(&mut buffer).unwrap();
  return buffer.trim().to_string();
}

fn main() {
  println!("{}", solve());
}
0