結果

問題 No.697 池の数はいくつか
ユーザー cympfhcympfh
提出日時 2018-06-13 15:48:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 919 ms / 6,000 ms
コード長 2,331 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 171,116 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-25 20:06:14
合計ジャッジ時間 9,031 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 0 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 0 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 102 ms
6,948 KB
testcase_25 AC 102 ms
6,940 KB
testcase_26 AC 100 ms
6,944 KB
testcase_27 AC 103 ms
6,944 KB
testcase_28 AC 102 ms
6,944 KB
testcase_29 AC 887 ms
11,392 KB
testcase_30 AC 915 ms
11,008 KB
testcase_31 AC 883 ms
11,392 KB
testcase_32 AC 919 ms
11,008 KB
testcase_33 AC 914 ms
11,136 KB
testcase_34 AC 913 ms
11,008 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: constant `M` is never used
  --> main.rs:26:7
   |
26 | const M: usize = 1_000_000_007;
   |       ^
   |
   = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let h: usize = sc.cin();
    let w: usize = sc.cin();
    let mut memo = vec![vec![false; w]; h];
    for i in 0..h {
        for j in 0..w {
            let d: usize = sc.cin();
            if d == 1 {
                memo[i][j] = true;
            }
        }
    }

    let mut ans = 0;

    for i in 0..h {
        for j in 0..w {

            if !memo[i][j] { continue }

            ans += 1;
            let mut stack = VecDeque::new();
            stack.push_back((i, j));

            while let Some((i, j)) = stack.pop_front() {
                if !memo[i][j] { continue }
                memo[i][j] = false;
                if i < h - 1 { stack.push_back((i+1, j)); }
                if i > 0 { stack.push_back((i-1, j)); }
                if j < w - 1 { stack.push_back((i, j+1)); }
                if j > 0 { stack.push_back((i, j-1)); }
            }
        }
    }

    put!(ans);

}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}
0