diff --git a/storage/zeta/rs/completed/1222.rs b/storage/zeta/rs/completed/1222.rs new file mode 100644 index 0000000..dbf3df0 --- /dev/null +++ b/storage/zeta/rs/completed/1222.rs @@ -0,0 +1,34 @@ +use std::cmp::max; +use std::io::{read_to_string, stdin}; +const MAX_PARTS: usize = 2000000; +fn main() { + let temp = read_to_string(stdin()).unwrap(); + let mut iter = temp + .split_ascii_whitespace() + .map(|x| x.parse::().unwrap()); + + let n = iter.next().unwrap(); + let mut parts = (0..n).map(|_| iter.next().unwrap()).collect::>(); + parts.sort(); + + let mut res = 0; + + let mut maps = vec![0; MAX_PARTS + 1]; + for p in parts { + maps[p] += 1; + } + + for d in 1..=MAX_PARTS { + let mut q = 0; + let mut cnt = 0; + for i in (0..=MAX_PARTS).step_by(d) { + q += d * maps[i]; + cnt += maps[i]; + } + if cnt < 2 { + continue; + } + res = max(res, q); + } + println!("{}", res); +} diff --git a/storage/zeta/rs/completed/34011.rs b/storage/zeta/rs/completed/34011.rs new file mode 100644 index 0000000..6f8929e --- /dev/null +++ b/storage/zeta/rs/completed/34011.rs @@ -0,0 +1,45 @@ +use std::cmp::max; +use std::io::{read_to_string, stdin}; + +fn main() { + let temp = read_to_string(stdin()).unwrap(); + let mut iter = temp + .split_ascii_whitespace() + .map(|x| x.parse::().unwrap()); + let mut n = iter.next().unwrap(); + let mut parents = (0..n - 1) + .map(|_| iter.next().unwrap() - 1) + .collect::>(); + + let mut edges = vec![vec![]; n]; + for (i, &p) in parents.iter().enumerate() { + edges[p].push(i + 1); + } + + let mut depthes = vec![0; n]; + let mut deq = vec![]; + deq.push((0, 0)); + let mut max_depth = 0; + while !deq.is_empty() { + let (u, d) = deq.pop().unwrap(); + depthes[d] += 1; + if edges[u].is_empty() { + max_depth = max(max_depth, d); + continue; + } + for &v in edges[u].iter() { + deq.push((v, d + 1)); + } + } + + let mut res = 0; + for d in 2..=n { + let mut q = 0; + for i in (0..=max_depth).step_by(d) { + q += depthes[i]; + } + res = max(res, q); + } + + println!("{}", res); +}