結果

問題 No.133 カードゲーム
ユーザー tabataba
提出日時 2024-08-01 10:53:01
言語 Rust
(1.77.0)
結果
AC  
実行時間 789 ms / 5,000 ms
コード長 1,771 bytes
コンパイル時間 11,749 ms
コンパイル使用メモリ 397,408 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-01 10:53:32
合計ジャッジ時間 28,678 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 422 ms
6,812 KB
testcase_01 AC 384 ms
6,940 KB
testcase_02 AC 399 ms
6,940 KB
testcase_03 AC 211 ms
6,940 KB
testcase_04 AC 600 ms
6,940 KB
testcase_05 AC 772 ms
6,940 KB
testcase_06 AC 780 ms
6,944 KB
testcase_07 AC 789 ms
6,940 KB
testcase_08 AC 593 ms
6,940 KB
testcase_09 AC 610 ms
6,944 KB
testcase_10 AC 752 ms
6,944 KB
testcase_11 AC 779 ms
6,940 KB
testcase_12 AC 772 ms
6,940 KB
testcase_13 AC 392 ms
6,940 KB
testcase_14 AC 596 ms
6,940 KB
testcase_15 AC 582 ms
6,940 KB
testcase_16 AC 780 ms
6,944 KB
testcase_17 AC 755 ms
6,944 KB
testcase_18 AC 771 ms
6,944 KB
testcase_19 AC 768 ms
6,944 KB
testcase_20 AC 752 ms
6,940 KB
testcase_21 AC 778 ms
6,940 KB
testcase_22 AC 776 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `BTreeSet`, `HashMap`, `hash::Hash`
 --> src/main.rs:2:19
  |
2 |     collections::{BTreeSet, HashMap},
  |                   ^^^^^^^^  ^^^^^^^
3 |     hash::Hash,
  |     ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::{
    collections::{BTreeSet, HashMap},
    hash::Hash,
};

fn main() {
    proconio::input! {
        n: usize,
        mut a: [u32; n],
        mut b: [u32; n],
    }
    let mut rng = Xorshift::new();
    let mut win = 0;
    for _ in 0..10000000 {
        shuffle(&mut a, &mut rng);
        shuffle(&mut b, &mut rng);
        let mut w = 0;
        for i in 0..n {
            if a[i] > b[i] {
                w += 1;
            }
        }
        if w > n / 2 {
            win += 1
        }
    }

    println!("{}", win as f64 / 10000000.);
}

fn shuffle<T>(x: &mut [T], rng: &mut Xorshift) {
    for i in 0..x.len() {
        let j = rng.rand(x.len() as u64) as usize;
        x.swap(i, j);
    }
}

#[derive(Debug)]
#[allow(dead_code)]
pub struct Xorshift {
    seed: u64,
}
impl Xorshift {
    #[allow(dead_code)]
    pub fn new() -> Xorshift {
        Xorshift {
            seed: 0xf0fb588ca2196dac,
        }
    }
    #[allow(dead_code)]
    pub fn with_seed(seed: u64) -> Xorshift {
        Xorshift { seed: seed }
    }
    #[inline]
    #[allow(dead_code)]
    pub fn next(&mut self) -> u64 {
        self.seed = self.seed ^ (self.seed << 13);
        self.seed = self.seed ^ (self.seed >> 7);
        self.seed = self.seed ^ (self.seed << 17);
        self.seed
    }
    #[inline]
    #[allow(dead_code)]
    pub fn rand(&mut self, m: u64) -> u64 {
        self.next() % m
    }
    #[inline]
    #[allow(dead_code)]
    // 0.0 ~ 1.0
    pub fn randf(&mut self) -> f64 {
        use std::mem;
        const UPPER_MASK: u64 = 0x3FF0000000000000;
        const LOWER_MASK: u64 = 0xFFFFFFFFFFFFF;
        let tmp = UPPER_MASK | (self.next() & LOWER_MASK);
        let result: f64 = unsafe { mem::transmute(tmp) };
        result - 1.0
    }
}
0