From 028357635acfbe86177aeca83ce9fcfe3bb32cdf Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 12 Jan 2026 17:59:34 -0800 Subject: [PATCH] complete 9414.rs 17392.rs 26853.rs --- storage/zeta/rs/completed/17392.rs | 30 +++++++++++++++++ storage/zeta/rs/completed/26853.rs | 36 ++++++++++++++++++++ storage/zeta/rs/completed/9414.rs | 53 ++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 storage/zeta/rs/completed/17392.rs create mode 100644 storage/zeta/rs/completed/26853.rs create mode 100644 storage/zeta/rs/completed/9414.rs diff --git a/storage/zeta/rs/completed/17392.rs b/storage/zeta/rs/completed/17392.rs new file mode 100644 index 0000000..62edc51 --- /dev/null +++ b/storage/zeta/rs/completed/17392.rs @@ -0,0 +1,30 @@ +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 n = iter.next().unwrap(); + let m = iter.next().unwrap(); + + let total_expected_happinesses: i64 = (0..n).map(|_| iter.next().unwrap()).sum(); + + let res = if total_expected_happinesses + n >= m { + 0 + } else { + let actual_non_happy_day = m - (total_expected_happinesses + n); + let d = actual_non_happy_day / (n + 1); + let remain = actual_non_happy_day % (n + 1); + + if remain > 0 { + remain * ((d + 1) * (d + 2) * (2 * d + 3) / 6) + + (n + 1 - remain) * (d * (d + 1) * (2 * d + 1) / 6) + } else { + (d * (d + 1) * (2 * d + 1) / 6) * (n + 1) + } + }; + + println!("{}", res); +} diff --git a/storage/zeta/rs/completed/26853.rs b/storage/zeta/rs/completed/26853.rs new file mode 100644 index 0000000..86591b0 --- /dev/null +++ b/storage/zeta/rs/completed/26853.rs @@ -0,0 +1,36 @@ +use std::io::stdin; + +fn main() { + let mut lines = stdin().lines(); + let line = lines.next().unwrap().unwrap(); + let mut iter = line.split(' ').map(|x| x.parse::().unwrap()); + + let n = iter.next().unwrap(); + let m = iter.next().unwrap(); + + let words = (0..n) + .map(|_| lines.next().unwrap().unwrap().trim().chars().collect()) + .collect::>>(); + + let mut cnts = vec![vec![0; 26]; m]; + for i in 0..n { + for (j, &ch) in words[i].iter().enumerate() { + let idx = (ch as u8 - 'a' as u8) as usize; + cnts[j][idx] += 1; + } + } + + let mut total_penalty = 0; + for i in 0..m { + let mut max_value = 0; + for j in 0..26 { + let value = cnts[i][j]; + if value > max_value { + max_value = value; + } + } + total_penalty += n - max_value; + } + + println!("{}", total_penalty); +} diff --git a/storage/zeta/rs/completed/9414.rs b/storage/zeta/rs/completed/9414.rs new file mode 100644 index 0000000..aa864b1 --- /dev/null +++ b/storage/zeta/rs/completed/9414.rs @@ -0,0 +1,53 @@ +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 tc = iter.next().unwrap(); + + const MONEY_LIMIT_U64: u64 = 2_500_000; + const MONEY_LIMIT_F64: f64 = MONEY_LIMIT_U64 as f64; + + for _ in 0..tc { + let prices = { + let mut prices = vec![]; + + let mut value = iter.next().unwrap() as u64; + + while value != 0 { + prices.push(value); + value = iter.next().unwrap() as u64; + } + + prices.sort(); + prices.reverse(); + prices + }; + + let mut flag_expensive = false; + let mut total_price = 0; + for (t, &price) in prices.iter().enumerate() { + let t = t + 1; + let critea = MONEY_LIMIT_F64.powf(1.0 / (t as f64)).ceil() as u64; + if price > critea { + flag_expensive = true; + break; + } + + total_price += price.pow(t as u32); + } + if total_price > MONEY_LIMIT_U64 { + flag_expensive = true; + } + + if flag_expensive { + println!("Too expensive"); + } else { + println!("{}", 2 * total_price); + } + } +}