結果

問題 No.2509 Beam Shateki
ユーザー 👑 KA37RIKA37RI
提出日時 2023-09-26 19:08:07
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,860 bytes
コンパイル時間 2,913 ms
コンパイル使用メモリ 146,620 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-26 19:08:19
合計ジャッジ時間 6,605 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,756 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
権限があれば一括ダウンロードができます

ソースコード

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));
    outer.push((h + 1, 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 &(ox2, oy2) in outer.iter() {
      for &(dx1, dy1) in dir.iter() {
        for &(dx2, dy2) in dir.iter() {
          let mut score = 0;
          let mut placed = vec![vec![true; w]; h];
          let mut px = ox1;
          let mut py = oy1;
          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; }
            score += a[px-1][py-1];
            placed[px-1][py-1] = false;
          }
          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] {
              score += a[px-1][py-1];
              placed[px-1][py-1] = false;
            }
          }
          ans = ans.max(score);
        }
      }
    }
  }
  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