complete 9414.rs 17392.rs 26853.rs

This commit is contained in:
2026-01-12 17:59:34 -08:00
parent e24c586ce4
commit 028357635a
3 changed files with 119 additions and 0 deletions

View File

@@ -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::<usize>().unwrap());
let n = iter.next().unwrap();
let m = iter.next().unwrap();
let words = (0..n)
.map(|_| lines.next().unwrap().unwrap().trim().chars().collect())
.collect::<Vec<Vec<char>>>();
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);
}