結果
| 問題 | No.133 カードゲーム |
| コンテスト | |
| ユーザー |
kinodjnz
|
| 提出日時 | 2024-05-10 01:27:50 |
| 言語 | Rust (1.97.1 + proconio + num + itertools + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 0 ms / 5,000 ms |
| + 847µs | |
| コード長 | 1,258 bytes |
| 記録 | |
| コンパイル時間 | 5,338 ms |
| コンパイル使用メモリ | 198,232 KB |
| 実行使用メモリ | 9,900 KB |
| 最終ジャッジ日時 | 2026-10-04 20:03:13 |
| 合計ジャッジ時間 | 8,028 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
use itertools::Itertools;
use std::io::Read;
use std::cmp::Ordering;
fn factorial(x: usize) -> usize {
if x == 0 {
1
} else {
x * factorial(x - 1)
}
}
fn solve(n: usize, a: &[i64], b: &[i64]) -> f64 {
let mut a_wins = 0;
for pa in a.iter().permutations(n) {
for pb in b.iter().permutations(n) {
let m = pa
.iter()
.zip(pb.iter())
.map(|(x, y)| match x.cmp(y) {
Ordering::Greater => 1,
Ordering::Less => -1,
Ordering::Equal => 0,
})
.sum::<i64>();
if m > 0 {
a_wins += 1;
}
}
}
(a_wins as f64) / (factorial(n).pow(2) as f64)
}
fn main() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let a: Vec<i64> = (0..n)
.map(|_| iter.next().unwrap().parse().unwrap())
.collect();
let b: Vec<i64> = (0..n)
.map(|_| iter.next().unwrap().parse().unwrap())
.collect();
let result = solve(n, &a, &b);
println!("{}", result);
}
kinodjnz