#![allow(non_snake_case)] #![allow(unused_imports)] use crate::lib::Permutation; use proconio::{ fastout, input, input_interactive, marker::{Chars, Isize1, Usize1}, }; use std::vec; #[allow(dead_code)] // const MOD: i64 = 1_000_000_007; // const MOD : i64 = 1_000_000_009; const MOD: i64 = 998_244_353; #[allow(dead_code)] const INF: i64 = 1_010_000_000_000_000_017; const DX: [i64; 4] = [0, 0, 1, -1]; const DY: [i64; 4] = [1, -1, 0, 0]; #[allow(non_snake_case)] fn main() { input!(N:usize, A:[usize;N], B:[usize;N]); let mut count_match = 0; let mut count_win_A = 0; let p = Permutation::new(&(0..N).collect()); for perm_A in p.clone() { for perm_B in p.clone() { count_match += 1; let mut win_A = 0; for i in 0..N { if A[perm_A[i]] > B[perm_B[i]] { win_A += 1; } } if win_A > N / 2 { count_win_A += 1; } } } println!("{}", count_win_A as f64 / count_match as f64) } pub mod lib { #[derive(Clone)] pub struct Permutation { v: Vec, l: Vec, not_start: bool, } impl Permutation { pub fn new(v: &Vec) -> Permutation { Permutation { l: vec![0; v.len()], v: v.clone(), not_start: true, } } } impl Iterator for Permutation { type Item = Vec; fn next(&mut self) -> Option> { // non-permutated vector if self.not_start { self.not_start = false; return Some(self.v.clone()); } for n in 0..self.v.len() { if self.l[n] < n { if (n + 1) % 2 == 1 { self.v.swap(0, n); self.l[n] += 1; } else { self.v.swap(self.l[n], n); self.l[n] += 1; } return Some(self.v.clone()); } else { self.l[n] = 0 } } return None; } } }