結果

問題 No.43 野球の試合
ユーザー tonyu0tonyu0
提出日時 2020-03-24 21:30:28
言語 Rust
(1.77.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,698 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 170,316 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 08:31:23
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 29 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

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 grid: Vec<Vec<char>> = (0..n)
        .map(|_| itr.next().unwrap().chars().collect())
        .collect();
    let mut m = Vec::new();
    for i in 0..n {
        for j in i + 1..n {
            if grid[i][j] == '-' {
                m.push((i, j));
            }
        }
    }

    let mut ans = 10;
    for bit in 0..(1 << m.len()) {
        let mut now = grid.clone();
        let mut point = Vec::new();
        let mut rank = Vec::new();
        for i in 0..m.len() {
            if bit >> i & 1 == 1 {
                now[m[i].0][m[i].1] = 'o';
                now[m[i].1][m[i].0] = 'x';
            } else {
                now[m[i].1][m[i].0] = 'o';
                now[m[i].0][m[i].1] = 'x';
            }
        }

        for i in 0..n {
            let mut p = 0;
            for j in 0..n {
                if i != j {
                    if now[i][j] == 'o' {
                        p += 1;
                    }
                }
            }
            point.push((p, i));
            rank.push(p);
        }
        point.sort_by(|a, b| b.0.cmp(&a.0));
        let mut b = rank.clone();
        b.sort();
        b.reverse();
        b.dedup();
        let mut c = std::collections::HashMap::new();
        for i in 0..b.len() {
            c.insert(b[i], i);
        }
        for i in 0..n {
            if point[i].1 == 0 {
                ans = std::cmp::min(ans, c[&point[i].0] + 1);
            }
        }
    }
    println!("{}", ans);
}
0