結果
問題 |
No.1345 Beautiful BINGO
|
ユーザー |
|
提出日時 | 2021-01-16 19:22:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,787 bytes |
コンパイル時間 | 16,189 ms |
コンパイル使用メモリ | 378,212 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 00:40:46 |
合計ジャッジ時間 | 24,761 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 RE * 36 |
コンパイルメッセージ
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
ソースコード
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); }