https://atcoder.jp/contests/abc337/tasks/abc337_e
2進数で考えて、1回ごとに各桁を決めます。すなわち、i桁目が1になるものだけを友人iに
// Bad Juice #![allow(non_snake_case)] use std::cmp::min; //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } //////////////////// process //////////////////// fn digits(n: usize, b: usize) -> Vec<usize> { let mut ds: Vec<usize> = vec![]; let mut m = n; while m > 0 { let d = m % b; ds.push(d); m /= b } ds } fn print_vec(v: Vec<usize>) { println!("{}", v.into_iter().map(|n| n.to_string()). collect::<Vec<String>>(). join(" ")) } fn output_friend(e: usize, N: usize) { let p: usize = 1 << e; let mut v: Vec<usize> = vec![]; for j in (p..N).step_by(p*2) { for k in j..min(N, j+p) { v.push(k+1) } } v.insert(0, v.len()); print_vec(v); } fn value(s: String) -> usize { let bs: Vec<u8> = s.chars().map(|c| (c as u8) - ('0' as u8)).collect(); bs.into_iter().rev().fold(0, |x, y| x*2 + (y as usize)) + 1 } fn F(N: usize) -> usize { let ds = digits(N-1, 2); let M = ds.len(); println!("{}", M); for e in 0..ds.len() { output_friend(e, N); } let s: String = read(); value(s) } fn main() { let N = read(); println!("{}", F(N)) }