結果

問題 No.2509 Beam Shateki
ユーザー haihamabossuhaihamabossu
提出日時 2023-10-20 22:17:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,207 ms / 2,000 ms
コード長 3,686 bytes
コンパイル時間 7,884 ms
コンパイル使用メモリ 186,068 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-20 22:18:37
合計ジャッジ時間 39,357 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 124 ms
4,348 KB
testcase_04 AC 124 ms
4,348 KB
testcase_05 AC 124 ms
4,348 KB
testcase_06 AC 119 ms
4,348 KB
testcase_07 AC 130 ms
4,348 KB
testcase_08 AC 125 ms
4,348 KB
testcase_09 AC 125 ms
4,348 KB
testcase_10 AC 125 ms
4,348 KB
testcase_11 AC 126 ms
4,348 KB
testcase_12 AC 125 ms
4,348 KB
testcase_13 AC 1,184 ms
4,348 KB
testcase_14 AC 1,185 ms
4,348 KB
testcase_15 AC 1,175 ms
4,348 KB
testcase_16 AC 1,184 ms
4,348 KB
testcase_17 AC 1,172 ms
4,348 KB
testcase_18 AC 1,182 ms
4,372 KB
testcase_19 AC 1,207 ms
4,372 KB
testcase_20 AC 1,188 ms
4,348 KB
testcase_21 AC 1,184 ms
4,348 KB
testcase_22 AC 1,187 ms
4,348 KB
testcase_23 AC 1,181 ms
4,348 KB
testcase_24 AC 1,197 ms
4,348 KB
testcase_25 AC 1,184 ms
4,348 KB
testcase_26 AC 1,182 ms
4,348 KB
testcase_27 AC 1,160 ms
4,348 KB
testcase_28 AC 1,183 ms
4,348 KB
testcase_29 AC 1,184 ms
4,348 KB
testcase_30 AC 1,180 ms
4,348 KB
testcase_31 AC 1,193 ms
4,348 KB
testcase_32 AC 1,175 ms
4,348 KB
testcase_33 AC 16 ms
4,348 KB
testcase_34 AC 261 ms
4,348 KB
testcase_35 AC 552 ms
4,348 KB
testcase_36 AC 85 ms
4,348 KB
testcase_37 AC 19 ms
4,348 KB
testcase_38 AC 99 ms
4,348 KB
testcase_39 AC 86 ms
4,348 KB
testcase_40 AC 318 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 122 ms
4,348 KB
testcase_43 AC 711 ms
4,348 KB
testcase_44 AC 827 ms
4,348 KB
testcase_45 AC 79 ms
4,348 KB
testcase_46 AC 165 ms
4,348 KB
testcase_47 AC 847 ms
4,348 KB
testcase_48 AC 198 ms
4,348 KB
testcase_49 AC 360 ms
4,348 KB
testcase_50 AC 436 ms
4,348 KB
testcase_51 AC 16 ms
4,348 KB
testcase_52 AC 285 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 1 ms
4,348 KB
testcase_60 AC 1 ms
4,348 KB
testcase_61 AC 0 ms
4,348 KB
testcase_62 AC 1 ms
4,348 KB
testcase_63 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod scanner {

    pub struct Scanner {
        buf: Vec<String>,
    }

    impl Scanner {
        pub fn new() -> Self {
            Self { buf: vec![] }
        }

        pub fn new_from(source: &str) -> Self {
            let source = String::from(source);
            let buf = Self::split(source);
            Self { buf }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            loop {
                if let Some(x) = self.buf.pop() {
                    return x.parse().ok().expect("");
                }
                let mut source = String::new();
                std::io::stdin().read_line(&mut source).expect("");
                self.buf = Self::split(source);
            }
        }

        fn split(source: String) -> Vec<String> {
            source
                .split_whitespace()
                .rev()
                .map(String::from)
                .collect::<Vec<_>>()
        }
    }
}

use crate::scanner::Scanner;
use std::{collections::BTreeMap, io::Write};
fn main() {
    let mut scanner = Scanner::new();
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let t: usize = 1;
    for _ in 0..t {
        solve(&mut scanner, &mut out);
    }
}
fn solve(scanner: &mut Scanner, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let h = scanner.next::<usize>();
    let w = scanner.next::<usize>();
    let a = (0..h)
        .map(|_| (0..w).map(|_| scanner.next::<usize>()).collect::<Vec<_>>())
        .collect::<Vec<_>>();
    let mut sum = BTreeMap::<(usize, usize, usize, usize), usize>::new();
    let mut rev = BTreeMap::<(usize, usize), Vec<(usize, usize, usize, usize)>>::new();
    for i in 0..h {
        let key = (i, 0, 0, 1);
        let mut now = 0;
        for j in 0..w {
            now += a[i][j];
            rev.entry((i, j)).or_insert(vec![]).push(key);
        }
        sum.insert(key, now);
    }
    for j in 0..w {
        let key = (0, j, 1, 0);
        let mut now = 0;
        for i in 0..h {
            now += a[i][j];
            rev.entry((i, j)).or_insert(vec![]).push(key);
        }
        sum.insert(key, now);
    }
    for i in 0..h + w - 1 {
        let key = (i, 0, !0, 1);
        let mut now = 0;
        for j in 0..w {
            if i - j < h {
                now += a[i - j][j];
                rev.entry((i - j, j)).or_insert(vec![]).push(key);
            }
        }
        sum.insert(key, now);
    }
    for i in 0..h + w - 1 {
        let key = (i, w - 1, !0, !0);
        let mut now = 0;
        for j in 0..w {
            if i - j < h {
                now += a[i - j][w - j - 1];
                rev.entry((i - j, w - j - 1)).or_insert(vec![]).push(key);
            }
        }
        sum.insert(key, now);
    }
    let mut ans = 0;
    for (k1, v1) in &sum {
        for (k2, v2) in &sum {
            if k1 == k2 {
                ans = ans.max(*v1);
                continue;
            }
            let mut res = *v1 + *v2;
            let mut ci = k1.0;
            let mut cj = k1.1;
            for _ in 0..(h + w) * 2 + 10 {
                if ci < h && cj < w {
                    let mut count = 0;
                    for k3 in &rev[&(ci, cj)] {
                        if k1 == k3 || k2 == k3 {
                            count += 1;
                        }
                    }
                    if count == 2 {
                        res -= a[ci][cj];
                        break;
                    }
                }
                ci += k1.2;
                cj += k1.3;
            }
            ans = ans.max(res);
        }
    }
    writeln!(out, "{}", ans).unwrap();
}
0