AtCoder Beginner Contest 264 C

https://atcoder.jp/contests/abc264/tasks/abc264_c

どうしてもインデックスベースになりますね。

// Matrix Reducing
#![allow(non_snake_case)]

use itertools::Itertools;

type Matrix<T> = Vec<Vec<T>>;

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 read_matrix<T: std::str::FromStr>(H: usize) -> Matrix<T> {
    (0..H).map(|_| read_vec()).collect()
}

//////////////////// process ////////////////////

fn read_mat() -> Matrix<i32> {
    let v = read_vec();
    let H: usize = v[0];
    return read_matrix(H);
}

fn slice(A: &Matrix<i32>, is: &Vec<usize>, js: &Vec<usize>) -> Matrix<i32> {
    is.iter().map(|&i| js.iter().map(|&j| A[i][j]).collect()).collect()
}

fn equals(A: &Matrix<i32>, B: &Matrix<i32>) -> bool {
    let H = A.len();
    let W = A[0].len();
    (0..H).all(|i| (0..W).all(|j| A[i][j] == B[i][j]))
}

fn is_reducable(A: Matrix<i32>, B: Matrix<i32>) -> bool {
    let H1 = A.len();
    let W1 = A[0].len();
    let H2 = B.len();
    let W2 = B[0].len();
    for is in (0..H1).combinations(H2) {
        for js in (0..W1).combinations(W2) {
            if equals(&slice(&A, &is, &js), &B) {
                return true
            }
        }
    }
    return false
}

fn main() {
    let A = read_mat();
    let B = read_mat();
    println!("{}", if is_reducable(A, B) { "Yes" } else { "No" })
}