結果

問題 No.1345 Beautiful BINGO
ユーザー cympfhcympfh
提出日時 2021-01-16 15:00:50
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,904 bytes
コンパイル時間 12,545 ms
コンパイル使用メモリ 386,540 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-05 17:41:30
合計ジャッジ時間 14,377 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#![allow(unused_imports, unused_macros, dead_code)]
use std::{cmp::*, collections::*};

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();

    let mut x = vec![vec![0; n]; n];
    for i in 0..n {
        for j in 0..n {
            let a: u64 = sc.cin();
            x[i][j] = a;
        }
    }

    let mut ans = 0;
    for _ in 0..m {
        ans += greedy(&mut x);
    }
    put!(ans);
}

fn greedy(x: &mut Vec<Vec<u64>>) -> u64 {
    let n = x.len();
    let mut mx = 200 * n as u64;
    {
        let s: u64 = (0..n).map(|i| x[i][i]).sum();
        if s > 0 {
            mx = min!(mx, s);
        }
    }
    {
        let s: u64 = (0..n).map(|i| x[i][n - 1 - i]).sum();
        if s > 0 {
            mx = min!(mx, s);
        }
    }
    for i in 0..n {
        let s: u64 = (0..n).map(|j| x[i][j]).sum();
        if s > 0 {
            mx = min!(mx, s);
        }
    }
    for i in 0..n {
        let s: u64 = (0..n).map(|j| x[j][i]).sum();
        if s > 0 {
            mx = min!(mx, s);
        }
    }
    {
        let s: u64 = (0..n).map(|i| x[i][i]).sum();
        if s == mx {
            for i in 0..n {
                x[i][i] = 0;
            }
            return mx;
        }
    }
    {
        let s: u64 = (0..n).map(|i| x[i][n - 1 - i]).sum();
        if s == mx {
            for i in 0..n {
                x[i][n - 1 - i] = 0;
            }
            return mx;
        }
    }
    for i in 0..n {
        let s: u64 = (0..n).map(|j| x[i][j]).sum();
        if s == mx {
            for j in 0..n {
                x[i][j] = 0;
            }
            return mx;
        }
    }
    for i in 0..n {
        let s: u64 = (0..n).map(|j| x[j][i]).sum();
        if s == mx {
            for j in 0..n {
                x[j][i] = 0;
            }
            return mx;
        }
    }
    return 0;
}

// {{{
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Self {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}
fn flush() {
    std::io::stdout().flush().unwrap();
}
#[macro_export]
macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
#[macro_export]
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
#[macro_export]
macro_rules! trace {
    ($x:expr) => {
        #[cfg(debug_assertions)]
        eprintln!(">>> {} = {:?}", stringify!($x), $x)
    };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
#[macro_export]
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}
// }}}
0