Submission #8578704


Source Code Expand

Copy
use std::io::*;
use std::str::FromStr;

fn main() {
    let h: usize = read();
    let w: usize = read();
    let k: usize = read();
    let s: Vec<Vec<char>> = (0..h).map(|_| read::<String>().chars().collect()).collect();

    let mut ans: Vec<Vec<usize>> = vec![vec![0; w]; h];

    let mut cnt = 1;
    let mut blank: Vec<usize> = vec![];
    for i in 0..h {
        let mut found = false;
        for j in 0..w {
            if s[i][j] == '#' {
                found = true;
                ans[i][j] = cnt;
                cnt += 1;
            } else if j > 0 && ans[i][j-1] > 0 {
                ans[i][j] = ans[i][j-1];
            }
        }
        if !found {
            blank.push(i);
        }
    }
    for i in 0..h {
        for j in (0..w).rev() {
            if ans[i][j] == 0 && j < w-1 && ans[i][j+1] > 0 {
                ans[i][j] = ans[i][j+1];
            }
        }
    }
    for i in 0..blank.len() {
        let i = blank[i];
        if i > 0 && ans[i-1][0] > 0 {
            for j in 0..w {
                ans[i][j] = ans[i-1][j];
            }
        }
    }
    for i in (0..blank.len()).rev() {
        let i = blank[i];
        if i < h-1 && ans[i+1][0] > 0 {
            for j in 0..w {
                ans[i][j] = ans[i+1][j];
            }
        }
    }

    for i in 0..h {
        for j in 0..w {
            if j > 0 {
                print!(" ");
            }
            print!("{}", ans[i][j]);
        }
        println!();
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

Submission Info

Submission Time
Task C - Strawberry Cakes
User mds_boy
Language Rust (1.15.1)
Score 400
Code Size 1866 Byte
Status AC
Exec Time 27 ms
Memory 4860 KB

Compile Error

warning: unused variable: `k`, #[warn(unused_variables)] on by default
 --> ./Main.rs:7:9
  |
7 |     let k: usize = read();
  |         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 41
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
in01.txt AC 2 ms 4352 KB
in02.txt AC 2 ms 4352 KB
in03.txt AC 2 ms 4352 KB
in04.txt AC 2 ms 4352 KB
in05.txt AC 2 ms 4352 KB
in06.txt AC 2 ms 4352 KB
in07.txt AC 2 ms 4352 KB
in08.txt AC 2 ms 4352 KB
in09.txt AC 2 ms 4352 KB
in10.txt AC 2 ms 4352 KB
in11.txt AC 2 ms 4352 KB
in12.txt AC 2 ms 4476 KB
in13.txt AC 2 ms 4352 KB
in14.txt AC 2 ms 4352 KB
in15.txt AC 2 ms 4352 KB
in16.txt AC 2 ms 4352 KB
in17.txt AC 27 ms 4732 KB
in18.txt AC 27 ms 4860 KB
in19.txt AC 26 ms 4860 KB
in20.txt AC 27 ms 4732 KB
in21.txt AC 26 ms 4604 KB
in22.txt AC 26 ms 4604 KB
in23.txt AC 2 ms 4352 KB
in24.txt AC 2 ms 4352 KB
in25.txt AC 26 ms 4604 KB
in26.txt AC 27 ms 4604 KB
in27.txt AC 2 ms 4352 KB
in28.txt AC 26 ms 4732 KB
in29.txt AC 27 ms 4860 KB
in30.txt AC 27 ms 4860 KB
in31.txt AC 27 ms 4860 KB
in32.txt AC 27 ms 4860 KB
in33.txt AC 26 ms 4860 KB
in34.txt AC 26 ms 4860 KB
in35.txt AC 26 ms 4604 KB
in36.txt AC 27 ms 4732 KB
in37.txt AC 27 ms 4732 KB
in38.txt AC 27 ms 4732 KB
sample_01.txt AC 2 ms 4352 KB
sample_02.txt AC 2 ms 4352 KB
sample_03.txt AC 2 ms 4352 KB