https://www.acmicpc.net/problem/7569


수정 전 코드
use std::{
    collections::VecDeque,
    io::{stdinRead},
};

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    let (mnh): (usize__= {
        let mut iter = buf.split_whitespace().map(|xx.parse().unwrap());
        (
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
        )
    };

    buf.clear();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tomato = buf.split_whitespace();

    let mut tomato_box = vec![vec![vec![truem]; n]; h];
    let mut queue = VecDeque::new();
    let mut unripe = 0;
    for (zlayerin tomato_box.iter_mut().enumerate() {
        for (yrowin layer.iter_mut().enumerate() {
            for (xvaluein row.iter_mut().enumerate() {
                match tomato.next().unwrap() {
                    "1" => queue.push_back((zyx)),
                    "0" => {
                        *value = false;
                        unripe += 1;
                    }
                    "-1" => {}
                    _ => unreachable!(),
                }
            }
        }
    }

    let mut count = -1;
    while !queue.is_empty() {
        for _ in 0..queue.len() {
            let (zyx= queue.pop_front().unwrap();

            let mut next = Vec::with_capacity(6);
            if z > 0 {
                next.push((z - 1yx));
            }
            if z < h - 1 {
                next.push((z + 1yx));
            }
            if y > 0 {
                next.push((zy - 1x));
            }
            if y < n - 1 {
                next.push((zy + 1x));
            }
            if x > 0 {
                next.push((zyx - 1));
            }
            if x < m - 1 {
                next.push((zyx + 1));
            }

            for (next_znext_ynext_xin next {
                if !tomato_box[next_z][next_y][next_x] {
                    tomato_box[next_z][next_y][next_x= true;
                    queue.push_back((next_znext_ynext_x));
                    unripe -= 1;
                }
            }
        }
        count += 1;
    }

    if unripe > 0 {
        println!("-1");
    } else {
        println!("{}"count);
    }
}


use std::{
    collections::VecDeque,
    io::{stdinRead},
};

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    let (mnh): (u8__= {
        let mut iter = buf.split_whitespace().map(|xx.parse().unwrap());
        (
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
        )
    };

    buf.clear();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tomato = buf.split_whitespace();

    let mut tomato_box = vec![vec![vec![truem as usize]; n as usize]; h as usize];
    let mut queue = VecDeque::new();
    let mut unripe = 0;
    for (zlayerin tomato_box.iter_mut().enumerate() {
        for (yrowin layer.iter_mut().enumerate() {
            for (xvaluein row.iter_mut().enumerate() {
                match tomato.next().unwrap() {
                    "1" => queue.push_back((z as u8y as u8x as u8)),
                    "0" => {
                        *value = false;
                        unripe += 1;
                    }
                    "-1" => {}
                    _ => unreachable!(),
                }
            }
        }
    }

    let mut count = -1;
    while !queue.is_empty() {
        for _ in 0..queue.len() {
            let (zyx= queue.pop_front().unwrap();

            let mut next_closer = |next_znext_ynext_x| {
                let next_position = tomato_box
                    .get_mut(next_z as usize)
                    .unwrap()
                    .get_mut(next_y as usize)
                    .unwrap()
                    .get_mut(next_x as usize)
                    .unwrap();
                if !*next_position {
                    *next_position = true;
                    queue.push_back((next_znext_ynext_x));
                    unripe -= 1;
                }
            };

            if z > 0 {
                next_closer(z - 1yx);
            }
            if z < h - 1 {
                next_closer(z + 1yx);
            }
            if y > 0 {
                next_closer(zy - 1x);
            }
            if y < n - 1 {
                next_closer(zy + 1x);
            }
            if x > 0 {
                next_closer(zyx - 1);
            }
            if x < m - 1 {
                next_closer(zyx + 1);
            }
        }
        count += 1;
    }

    if unripe > 0 {
        println!("-1");
    } else {
        println!("{}"count);
    }
}


이전 시도사진


↑ 이건 내 시도들


30ms 나오는 사람들은 뭐가 다른거임

피드백 받고 만족함