結果
| 問題 |
No.2509 Beam Shateki
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-26 19:08:07 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,860 bytes |
| コンパイル時間 | 11,632 ms |
| コンパイル使用メモリ | 377,700 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-07-19 13:03:55 |
| 合計ジャッジ時間 | 15,968 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 60 |
ソースコード
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());
}