結果
問題 | No.2509 Beam Shateki |
ユーザー |
👑 |
提出日時 | 2023-09-26 20:40:06 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 983 ms / 2,000 ms |
コード長 | 1,759 bytes |
コンパイル時間 | 14,082 ms |
コンパイル使用メモリ | 377,360 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 23:13:13 |
合計ジャッジ時間 | 41,837 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 61 |
ソースコード
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()); }