https://atcoder.jp/contests/abc241/tasks/abc241_b
HashMapの値を変えるには、get_mutとメソッドを使うんですね。
// Pasta #![allow(non_snake_case)] use std::collections::HashMap; 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 count(A: Vec<i32>) -> HashMap<i32,i32> { let mut m = HashMap::<i32,i32>::new(); for x in A { let counter = m.entry(x).or_insert(0); *counter += 1; } return m } fn exists_all(mut m: HashMap<i32,i32>, B: Vec<i32>) -> bool { for b in B.iter() { match m.get_mut(b) { Some(0) => { return false }, Some(n) => { *n -= 1 }, None => { return false } } } return true } fn main() { let _v: Vec<usize> = read_vec(); let A: Vec<i32> = read_vec(); let B: Vec<i32> = read_vec(); let m = count(A); println!("{}", if exists_all(m, B) { "Yes" } else { "No" }) }