https://atcoder.jp/contests/abc243/tasks/abc243_b
HashSet
// Hit and Blow #![allow(non_snake_case)] use std::collections::HashSet; 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() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn num_match_at_same_positions(A: &Vec<i32>, B: &Vec<i32>) -> usize { let mut counter = 0; for (a, b) in A.iter().zip(B) { if a == b { counter += 1 } } return counter } fn num_match_at_different_positions(A: &Vec<i32>, B: &Vec<i32>) -> usize { let set_A: HashSet<i32> = A.iter().cloned().collect(); let set_B: HashSet<i32> = B.iter().cloned().collect(); let intersect: HashSet<&i32> = set_A.intersection(&set_B).collect(); return intersect.len() } fn main() { let _N: usize = read(); let A = read_vec(); let B = read_vec(); let num1 = num_match_at_same_positions(&A, &B); let num2 = num_match_at_different_positions(&A, &B); println!("{}", num1); println!("{}", num2 - num1) }