結果

問題 No.1345 Beautiful BINGO
ユーザー tonyu0tonyu0
提出日時 2021-01-16 19:22:07
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,787 bytes
コンパイル時間 17,511 ms
コンパイル使用メモリ 378,284 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 23:13:23
合計ジャッジ時間 25,726 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 1 ms
5,376 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
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 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 641 ms
5,376 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 642 ms
5,376 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 640 ms
5,376 KB
testcase_37 AC 7 ms
5,376 KB
testcase_38 RE -
testcase_39 AC 646 ms
5,376 KB
testcase_40 RE -
testcase_41 AC 302 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 RE -
testcase_44 RE -
testcase_45 AC 1 ms
5,376 KB
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 AC 644 ms
5,376 KB
testcase_53 AC 643 ms
5,376 KB
testcase_54 RE -
testcase_55 RE -
testcase_56 AC 640 ms
5,376 KB
testcase_57 AC 645 ms
5,376 KB
testcase_58 RE -
testcase_59 AC 642 ms
5,376 KB
testcase_60 AC 644 ms
5,376 KB
testcase_61 RE -
testcase_62 AC 642 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `S` should have a snake case name
  --> src/main.rs:18:9
   |
18 |     for S in 0..1 << n + 2 {
   |         ^ help: convert the identifier to snake case (notice the capitalization): `s`
   |
   = note: `#[warn(non_snake_case)]` on by default

ソースコード

diff #

use std::io::*;
const INF: usize = 1usize << 60;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<Vec<usize>> = (0..n)
        .map(|_| {
            (0..n)
                .map(|_| itr.next().unwrap().parse().unwrap())
                .collect()
        })
        .collect();

    let mut ans = INF;
    for S in 0..1 << n + 2 {
        let cnt = (S as u32).count_ones() as usize;

        let mut used = vec![vec![false; n]; n];
        let mut cost = 0;
        for i in 0..n {
            if S >> i & 1 == 1 {
                for j in 0..n {
                    cost += a[i][j];
                    used[i][j] = true;
                }
            }
        }
        if S >> n & 1 == 1 {
            for i in 0..n {
                if !used[i][i] {
                    cost += a[i][i];
                    used[i][i] = true;
                }
            }
        }
        if S >> n + 1 & 1 == 1 {
            for i in 0..n {
                if !used[n - 1 - i][i] {
                    cost += a[n - 1 - i][i];
                    used[n - 1 - i][i] = true;
                }
            }
        }
        let mut b = Vec::new();
        for j in 0..n {
            let mut tmp = 0;
            for i in 0..n {
                if !used[i][j] {
                    tmp += a[i][j];
                }
            }
            b.push(tmp);
        }
        b.sort();
        if m >= cnt {
            for i in 0..m - cnt {
                cost += b[i];
            }
        }
        ans = std::cmp::min(ans, cost);
    }
    println!("{}", ans);
}
0