結果
| 問題 |
No.133 カードゲーム
|
| ユーザー |
|
| 提出日時 | 2020-04-04 11:17:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,360 bytes |
| コンパイル時間 | 12,870 ms |
| コンパイル使用メモリ | 378,768 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-03 07:06:45 |
| 合計ジャッジ時間 | 14,055 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
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 win = 0.0;
permutation(n, &mut p, &mut used, &mut all);
for i in 0..all.len() {
let mut cnt = 0i32;
for j in 0..n {
if a[all[i][j]] > b[j] {
cnt += 1;
}
if a[all[i][j]] < b[j] {
cnt -= 1;
}
}
if cnt > 0 {
win += 1.0;
}
}
println!("{:.10}", win / (all.len() as f64));
}