結果

問題 No.2692 How Many Times Reached?
ユーザー ktmtr005ktmtr005
提出日時 2024-03-23 16:45:21
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 2,353 bytes
コンパイル時間 1,338 ms
コンパイル使用メモリ 183,132 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-23 16:45:25
合計ジャッジ時間 2,675 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 0 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 0 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 0 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 0 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 0 ms
6,676 KB
testcase_14 AC 0 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 0 ms
6,676 KB
testcase_18 AC 0 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 0 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 0 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 0 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 0 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 1 ms
6,676 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 1 ms
6,676 KB
testcase_37 AC 1 ms
6,676 KB
testcase_38 AC 1 ms
6,676 KB
testcase_39 AC 1 ms
6,676 KB
testcase_40 AC 1 ms
6,676 KB
testcase_41 AC 0 ms
6,676 KB
testcase_42 AC 1 ms
6,676 KB
testcase_43 AC 1 ms
6,676 KB
testcase_44 AC 1 ms
6,676 KB
testcase_45 AC 1 ms
6,676 KB
testcase_46 AC 0 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut sc = Scanner::new(std::io::stdin().lock(), 11111);
    let n: usize = sc.next();
    let s: Vec<Vec<char>> = (0..n)
        .map(|_n| sc.next::<String>().chars().collect::<Vec<char>>())
        .collect();

    let ans = solve(n, s);
    println!("{ans}");
}

fn solve(n: usize, s: Vec<Vec<char>>) -> usize {
    let mut cnt = 0;
    // vertical
    for ln in &s {
        if is_reach(ln) {
            cnt += 1;
        }
    }
    // horizotal
    for i in 0..n {
        let ln: Vec<char> = s.iter().map(|v| v[i]).collect();
        if is_reach(&ln) {
            cnt += 1;
        }
    }
    // diagonal
    {
        let ln1: Vec<char> = (0..n).map(|i| s[i][i]).collect();
        if is_reach(&ln1) {
            cnt += 1;
        }
        let ln2: Vec<char> = (0..n).map(|i| s[i][s.len() - 1 - i]).collect();
        if is_reach(&ln2) {
            cnt += 1;
        }
    }
    cnt
}

fn is_reach(ln: &[char]) -> bool {
    ln.iter().filter(|&&c| c == '.').count() == 1 && !ln.contains(&'B')
}

struct Scanner<R: std::io::BufRead> {
    reader: R,
    buf: Vec<u8>,
    pos: usize,
}
impl<R: std::io::BufRead> Scanner<R> {
    fn new(reader: R, capacity: usize) -> Self {
        Scanner {
            reader,
            buf: Vec::with_capacity(capacity),
            pos: 0,
        }
    }
    fn next<T: std::str::FromStr>(&mut self) -> T
    where
        T::Err: std::fmt::Debug,
    {
        if self.buf.is_empty() {
            self.read_next_line();
        }
        let mut start = None;
        loop {
            if self.pos == self.buf.len() {
                break;
            }
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) => self.pos += 1,
                (b'\n', false) => self.read_next_line(),
                (_, false) => start = Some(self.pos),
            }
        }
        let elem = unsafe { std::str::from_utf8_unchecked(&self.buf[start.unwrap()..self.pos]) };
        elem.parse()
            .unwrap_or_else(|_| panic!("{}", format!("failed parsing: {}", elem)))
    }
    fn read_next_line(&mut self) {
        self.pos = 0;
        self.buf.clear();
        if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
            panic!("Reached EOF");
        }
    }
}
0