Submission #67334295


Source Code Expand

use std::{collections::HashMap, io};

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

const DIR_R: [i32; 8] = [1, 0, -1, 0, 1, 1, -1, -1];
const DIR_C: [i32; 8] = [0, 1, 0, -1, 1, -1, 1, -1];

fn dfs(u: usize, adj: &Vec<Vec<usize>>, vis: &mut Vec<bool>) {
    vis[u] = true;
    for &v in &adj[u] {
        if !vis[v] {
            vis[v] = true;
            dfs(v, adj, vis);
        }
    }
}

fn main() {
    let mut scanner = Scanner::default();
    let (h, w, k): (i32, i32, usize) = (scanner.next(), scanner.next(), scanner.next());
    let mut rc = Vec::new();
    let mut mp = HashMap::new();
    for i in 0..k {
        let (r, c): (i32, i32) = (scanner.next(), scanner.next());
        rc.push((r, c));
        mp.insert((r, c), i);
    }

    let mut adj = vec![Vec::new(); k + 2];
    for (id, (r, c)) in rc.into_iter().enumerate() {
        for l in 0..8 {
            let nr = r + DIR_R[l];
            let nc = c + DIR_C[l];
            if nr <= 0 || nc > w {
                adj[id].push(k);
                adj[k].push(id);
            } else if nc <= 0 || nr > h {
                adj[id].push(k + 1);
                adj[k + 1].push(id);
            } else if let Some(&nid) = mp.get(&(nr, nc)) {
                adj[id].push(nid);
            }
        }
    }

    let mut vis = vec![false; k + 2];
    dfs(k, &adj, &mut vis);
    if vis[k + 1] {
        println!("No");
    } else {
        println!("Yes");
    }
}

Submission Info

Submission Time
Task G - Big Banned Grid
User maomao90
Language Rust (rustc 1.70.0)
Score 575
Code Size 1953 Byte
Status AC
Exec Time 116 ms
Memory 19456 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 575 / 575
Status
AC × 4
AC × 45
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 1932 KiB
00_sample_01.txt AC 1 ms 1916 KiB
00_sample_02.txt AC 1 ms 1948 KiB
00_sample_03.txt AC 1 ms 1924 KiB
01_random_04.txt AC 87 ms 13476 KiB
01_random_05.txt AC 88 ms 12980 KiB
01_random_06.txt AC 85 ms 12904 KiB
01_random_07.txt AC 87 ms 12740 KiB
01_random_08.txt AC 84 ms 13516 KiB
01_random_09.txt AC 82 ms 13488 KiB
01_random_10.txt AC 27 ms 6316 KiB
01_random_11.txt AC 10 ms 3636 KiB
01_random_12.txt AC 82 ms 12272 KiB
01_random_13.txt AC 33 ms 6920 KiB
01_random_14.txt AC 53 ms 10532 KiB
01_random_15.txt AC 62 ms 11200 KiB
01_random_16.txt AC 23 ms 6728 KiB
01_random_17.txt AC 22 ms 10560 KiB
01_random_18.txt AC 84 ms 19308 KiB
01_random_19.txt AC 78 ms 18764 KiB
01_random_20.txt AC 8 ms 4008 KiB
01_random_21.txt AC 10 ms 4156 KiB
01_random_22.txt AC 116 ms 17344 KiB
01_random_23.txt AC 115 ms 18056 KiB
01_random_24.txt AC 108 ms 17480 KiB
01_random_25.txt AC 115 ms 17816 KiB
01_random_26.txt AC 114 ms 18412 KiB
01_random_27.txt AC 110 ms 17856 KiB
01_random_28.txt AC 42 ms 9296 KiB
01_random_29.txt AC 60 ms 10084 KiB
01_random_30.txt AC 45 ms 9764 KiB
01_random_31.txt AC 93 ms 16076 KiB
01_random_32.txt AC 4 ms 2672 KiB
01_random_33.txt AC 72 ms 14684 KiB
01_random_34.txt AC 12 ms 4428 KiB
01_random_35.txt AC 63 ms 16596 KiB
01_random_36.txt AC 33 ms 9584 KiB
01_random_37.txt AC 103 ms 19456 KiB
01_random_38.txt AC 67 ms 17724 KiB
01_random_39.txt AC 1 ms 2088 KiB
01_random_40.txt AC 1 ms 1948 KiB
01_random_41.txt AC 1 ms 1972 KiB
01_random_42.txt AC 1 ms 1864 KiB
01_random_43.txt AC 1 ms 1924 KiB
01_random_44.txt AC 1 ms 1972 KiB