結果

問題 No.1345 Beautiful BINGO
ユーザー tonyu0tonyu0
提出日時 2021-01-16 19:23:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 1,811 bytes
コンパイル時間 13,666 ms
コンパイル使用メモリ 378,596 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 07:19:31
合計ジャッジ時間 20,698 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 0 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 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
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 0 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 13 ms
5,376 KB
testcase_26 AC 129 ms
5,376 KB
testcase_27 AC 576 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 133 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 583 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 133 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 115 ms
5,376 KB
testcase_39 AC 581 ms
5,376 KB
testcase_40 AC 282 ms
5,376 KB
testcase_41 AC 133 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 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 1 ms
5,376 KB
testcase_49 AC 0 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 571 ms
5,376 KB
testcase_54 AC 69 ms
5,376 KB
testcase_55 AC 232 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 542 ms
5,376 KB
testcase_58 AC 559 ms
5,376 KB
testcase_59 AC 567 ms
5,376 KB
testcase_60 AC 230 ms
5,376 KB
testcase_61 AC 343 ms
5,376 KB
testcase_62 AC 1 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;
        if cnt + n < m || cnt > m {
            continue;
        }

        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();
        for i in 0..m - cnt {
            cost += b[i];
        }
        ans = std::cmp::min(ans, cost);
    }
    println!("{}", ans);
}
0