use itertools::{Itertools, iproduct}; use proconio::input; // https://maguro.dev/blog/debug-macro/ #[allow(unused_macros)] macro_rules! debug { ($($a:expr),* $(,)*) => { #[cfg(debug_assertions)] eprintln!(concat!($("| ", stringify!($a), " = {:?} "),*, "|"), $(&$a),*); }; } fn main() { input! { n: usize, a: [usize; n], b: [usize; n] } let mut all = 0; let mut win = 0; for (u, v) in iproduct!(a.iter().permutations(n), b.iter().permutations(n)) { let mut cnt = 0; for i in 0..n { if u[i] > v[i] { cnt += 1; } } win += (n / 2 < cnt) as usize; all += 1; } debug!(all, win); let res = (win as f64) / (all as f64); println!("{res}"); }