https://atcoder.jp/contests/abc330/tasks/abc330_d
縦横でoの数を数えておきます。
// Counting Ls #![allow(non_snake_case)] //////////////////// 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 read_input() -> Vec<String> { let N: usize = read(); let S: Vec<String> = (0..N).map(|_| read()).collect(); S } fn count_rows(table: &Vec<Vec<char>>) -> Vec<usize> { table.iter().map(|v| v.iter().filter(|&&c| c == 'o').count()). collect::<Vec<usize>>() } fn count_cols(table: &Vec<Vec<char>>) -> Vec<usize> { let N = table.len(); (0..N).map(|j| (0..N).filter(|&i| table[i][j] == 'o').count()). collect::<Vec<usize>>() } fn F(S: Vec<String>) -> usize { let N = S.len(); let table: Vec<Vec<char>> = S.into_iter(). map(|s| s.chars().collect()).collect(); let rows = count_rows(&table); let cols = count_cols(&table); let mut s = 0; for i in 0..N { for j in 0..N { if table[i][j] == 'o' { s += (rows[i] - 1) * (cols[j] - 1) } } } s } fn main() { let S = read_input(); println!("{}", F(S)) }