提出 #20202805


ソースコード 拡げる

Copy
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

#[derive(Clone, Copy)]
enum Cell {
    Empty,
    Light,
    Block,
    Lit,
}

fn main() {
    input! {
        h: usize,
        w: usize,
        n: usize,
        m: usize,
        lights: [(Usize1, Usize1); n],
        blocks: [(Usize1, Usize1); m],
    }
    let mut field = vec![vec![Cell::Empty; w]; h];
    for (i, j) in lights {
        field[i][j] = Cell::Light;
    }
    for (i, j) in blocks {
        field[i][j] = Cell::Block;
    }
    field
        .iter_mut()
        .map(light_up)
        .for_each(drop);
    field
        .iter_mut()
        .map(|row| light_up(row.iter_mut().rev()))
        .for_each(drop);
    field
        .iter_mut()
        .transpose_mut()
        .map(light_up)
        .for_each(drop);
    field
        .iter_mut()
        .rev()
        .transpose_mut()
        .map(light_up)
        .for_each(drop);
    fn light_up<'a, Iter: IntoIterator<Item = &'a mut Cell>>(it: Iter) {
        let mut flag = false;
        for cell in it {
            match cell {
                Cell::Light => flag = true,
                Cell::Block => flag = false,
                _ => {
                    if flag {
                        *cell = Cell::Lit;
                    }
                }
            }
        }
    }
    let ans = field
        .iter()
        .flatten()
        .filter(|c| matches!(c, Cell::Light | Cell::Lit))
        .count();
    println!("{}", ans);
}
trait TransposeMut<'a, Elem, Iter, T>
where
    Elem: 'a,
    Iter: IntoIterator<Item = &'a mut Elem>,
    T: IntoIterator<Item = Iter>,
{
    fn transpose_mut(self) -> TransposedMut<'a, Elem, Iter>;
}

impl<'a, Elem, Iter, T> TransposeMut<'a, Elem, Iter, T> for T
where
    Elem: 'a,
    Iter: IntoIterator<Item = &'a mut Elem>,
    T: IntoIterator<Item = Iter>,
{
    fn transpose_mut(self) -> TransposedMut<'a, Elem, Iter> {
        TransposedMut {
            iters: self.into_iter().map(IntoIterator::into_iter).collect(),
        }
    }
}

struct TransposedMut<'a, Elem, Iter>
where
    Elem: 'a,
    Iter: IntoIterator<Item = &'a mut Elem>,
{
    iters: Vec<Iter::IntoIter>,
}

impl<'a, Elem, Iter> Iterator for TransposedMut<'a, Elem, Iter>
where
    Elem: 'a,
    Iter: IntoIterator<Item = &'a mut Elem>,
{
    type Item = Vec<&'a mut Elem>;
    fn next(&mut self) -> Option<Self::Item> {
        self.iters.iter_mut().map(Iterator::next).collect()
    }
}

提出情報

提出日時
問題 E - Akari
ユーザ toga57
言語 Rust (1.42.0)
得点 500
コード長 2595 Byte
結果 AC
実行時間 94 ms
メモリ 18548 KB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 20
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All handmade_00.txt, max_random_00.txt, max_random_01.txt, max_random_02.txt, max_random_03.txt, max_random_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, sample_01.txt, sample_02.txt, sample_03.txt, surrounded_00.txt
ケース名 結果 実行時間 メモリ
handmade_00.txt AC 9 ms 2100 KB
max_random_00.txt AC 84 ms 16196 KB
max_random_01.txt AC 82 ms 15988 KB
max_random_02.txt AC 83 ms 16016 KB
max_random_03.txt AC 85 ms 16060 KB
max_random_04.txt AC 84 ms 16024 KB
random_00.txt AC 94 ms 18464 KB
random_01.txt AC 92 ms 18548 KB
random_02.txt AC 2 ms 2116 KB
random_03.txt AC 2 ms 2212 KB
random_04.txt AC 56 ms 14468 KB
random_05.txt AC 51 ms 8932 KB
random_06.txt AC 54 ms 10084 KB
random_07.txt AC 80 ms 15868 KB
random_08.txt AC 15 ms 3332 KB
random_09.txt AC 65 ms 14744 KB
sample_01.txt AC 2 ms 2104 KB
sample_02.txt AC 2 ms 2144 KB
sample_03.txt AC 2 ms 2116 KB
surrounded_00.txt AC 85 ms 16384 KB