結果

問題 No.133 カードゲーム
ユーザー tonyu0
提出日時 2020-04-04 11:07:34
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,514 bytes
コンパイル時間 13,144 ms
コンパイル使用メモリ 383,628 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 07:04:08
合計ジャッジ時間 14,514 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn permutation(n: usize, p: &mut Vec<usize>, used: &mut Vec<bool>, all: &mut Vec<Vec<usize>>) {
    if p.len() == n {
        all.push(p.to_vec());
        return;
    }
    for i in 0..n {
        if !used[i] {
            p.push(i);
            used[i] = true;
            permutation(n, p, used, all);
            p.pop();
            used[i] = false;
        }
    }
}

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 a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let b: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut p: Vec<usize> = Vec::new();
    let mut used = vec![false; n];
    let mut all: Vec<Vec<usize>> = Vec::new();
    let mut cnt = 0;
    permutation(n, &mut p, &mut used, &mut all);
    for i in 0..all.len() {
        for j in 0..all.len() {
            let mut win = 0;
            let mut lose = 0;
            for k in 0..n {
                if a[all[i][k]] > b[all[j][k]] {
                    win += 1;
                }
                if a[all[i][k]] < b[all[j][k]] {
                    lose += 1;
                }
            }
            if win > lose {
                cnt += 1;
            }
        }
    }
    println!("{:.10}", (cnt as f64) / (all.len() * all.len()) as f64);
}
0