結果

問題 No.133 カードゲーム
コンテスト
ユーザー RheoTommy
提出日時 2020-11-05 22:25:49
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 2,580 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,221 ms
コンパイル使用メモリ 197,476 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-03 08:53:07
合計ジャッジ時間 5,657 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use crate::lib::Scanner;
use itertools::Itertools;
use std::collections::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.next_usize();
    let a = (0..n).map(|_| sc.next_usize()).collect_vec();
    let b = (0..n).map(|_| sc.next_usize()).collect_vec();
    let mut win = 0;
    let mut sum = 0;
    for c in (0..n).permutations(n) {
        for d in (0..n).permutations(n) {
            let mut score = 0;
            for i in 0..n {
                if a[c[i]] > b[d[i]] {
                    score += 1;
                } else {
                    score -= 1;
                }
            }
            if score > 0 {
                win += 1;
            }
            sum += 1;
        }
    }
    println!("{}", win as f64 / sum as f64);
}

pub mod lib {
    pub struct Scanner {
        buf: std::collections::VecDeque<String>,
    }

    impl Scanner {
        pub fn new() -> Self {
            Self {
                buf: std::collections::VecDeque::new(),
            }
        }

        fn scan_line(&mut self) {
            let mut flag = 0;
            while self.buf.is_empty() {
                let mut s = String::new();
                std::io::stdin().read_line(&mut s).unwrap();
                let mut iter = s.split_whitespace().peekable();
                if iter.peek().is_none() {
                    if flag >= 5 {
                        panic!("There is no input!");
                    }
                    flag += 1;
                    continue;
                }

                for si in iter {
                    self.buf.push_back(si.to_string());
                }
            }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            self.scan_line();
            self.buf
                .pop_front()
                .unwrap()
                .parse()
                .unwrap_or_else(|_| panic!("Couldn't parse!"))
        }

        pub fn next_usize(&mut self) -> usize {
            self.next()
        }

        pub fn next_isize(&mut self) -> isize {
            self.next()
        }

        pub fn next_chars(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_string(&mut self) -> String {
            self.next()
        }

        pub fn next_char(&mut self) -> char {
            self.next()
        }

        pub fn next_float(&mut self) -> f64 {
            self.next()
        }
    }
}
0