結果

問題 No.678 2Dシューティングゲームの必殺ビーム
ユーザー taotao54321taotao54321
提出日時 2018-09-28 23:29:18
言語 Rust
(1.77.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,552 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 170,940 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-04-20 12:04:05
合計ジャッジ時間 1,924 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
18,816 KB
testcase_01 AC 19 ms
18,688 KB
testcase_02 AC 18 ms
18,688 KB
testcase_03 AC 19 ms
18,688 KB
testcase_04 AC 19 ms
18,816 KB
testcase_05 AC 20 ms
18,816 KB
testcase_06 AC 19 ms
18,688 KB
testcase_07 AC 19 ms
18,816 KB
testcase_08 AC 20 ms
18,688 KB
testcase_09 AC 19 ms
18,816 KB
testcase_10 AC 19 ms
18,816 KB
testcase_11 AC 19 ms
18,688 KB
testcase_12 AC 20 ms
18,688 KB
testcase_13 AC 19 ms
18,816 KB
testcase_14 AC 19 ms
18,688 KB
testcase_15 AC 19 ms
18,688 KB
testcase_16 AC 19 ms
18,816 KB
testcase_17 AC 18 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut tokens = $s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };

    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut res = String::new();
            ::std::io::stdin().read_to_string(&mut res).unwrap();
            res
        };
        let mut tokens = s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($tokens:expr)  => {};
    ($tokens:expr,) => {};

    ($tokens:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($tokens, $t);
        input_inner! { $tokens $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($tokens:expr, ( $($t:tt),* )) => {
        ( $(read_value!($tokens, $t)),* )
    };

    ($tokens:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($tokens, $t)).collect::<Vec<_>>()
    };

    ($tokens:expr, chars) => {
        read_value!($tokens, String).chars().collect::<Vec<_>>()
    };

    ($tokens:expr, usize1) => {
        read_value!($tokens, usize) - 1
    };

    ($tokens:expr, $t:ty) => {
        $tokens.next().unwrap().parse::<$t>().expect("parse error")
    };
}

use std::cmp;

fn main() {
    const W: i64 = 1280;
    const H: i64 = 1680;

    input! {
        N: usize,
        L: i64,
        R: i64,
        E: [(i64,i64,i64,i64); N],
    }

    // 0-based
    let L = L-1;
    let R = R-1;
    let E: Vec<_> = E.iter().map(|(l,u,r,d)| (l-1,u-1,r-1,d-1)).collect();

    const EMPTY: i64 = -1;
    const BEAM:  i64 = -2;

    let mut screen = vec![vec![EMPTY; W as usize]; (H+1) as usize];
    for x in L..R+1 {
        screen[H as usize][x as usize] = BEAM;
    }

    for (i,&(l,u,r,d)) in E.iter().enumerate() {
        let l = cmp::max(l, 0);
        let u = cmp::max(u, 0);
        let r = cmp::min(r, W-1);
        let d = cmp::min(d, H-1);
        for y in u..d+1 { for x in l..r+1 {
            screen[y as usize][x as usize] = i as i64;
        }}
    }

    let mut ans = vec![0; N];
    for y in (0..H).rev() { for x in 0..W {
        let cur   = screen[y as usize][x as usize];
        let below = screen[(y+1) as usize][x as usize];
        if cur == EMPTY && below == BEAM {
            screen[y as usize][x as usize] = BEAM;
        }
        else if below == BEAM {
            ans[cur as usize] = 1;
        }
    }}

    for e in ans {
        println!("{}", e);
    }
}
0