Submission #15005813


Source Code Expand

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

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn dfs(n:usize,select:&mut Vec<Vec<bool>>,select_list:&mut Vec<bool>){

    if select_list.len() == n {
        select.push(select_list.to_vec());
        return;
    }

    for i in 0..2{
        if i == 0{
            select_list.push(true);
        }else{
            select_list.push(false);
        }
        dfs(n,select,select_list);
        select_list.pop();
    }
}

fn main() {
    let h:usize = read();
    let w:usize = read();
    let k:usize = read();
    let mut board:Vec<Vec<char>> = vec![vec![' '; w];h]; //列、行

    for i in 0..h{
        board[i] = read::<String>().chars().collect();
    }

    let mut h_select: Vec<Vec<bool>> = Vec::new();
    let mut select_list:Vec<bool> = Vec::new();
    dfs(h,&mut h_select,&mut select_list);
    let mut w_select: Vec<Vec<bool>> = Vec::new();
    let mut select_list:Vec<bool> = Vec::new();
    dfs(w,&mut w_select,&mut select_list);

    let mut ans = 0;

    for i in 0..h_select.len(){
        for j in 0..w_select.len(){
            let mut chk_board:Vec<Vec<char>> = board.clone(); //列、行
            for l in 0..h_select[i].len(){
                if h_select[i][l] == true {
                    for x in 0..w{
                        chk_board[l][x] = 'x';
                    }
                }
            }
            for m in 0..w_select[j].len(){
                if w_select[j][m] == true {
                    for x in 0..h{
                        chk_board[x][m] = 'x';
                    }
                }
            }
            //println!("h:{:?} j:{:?}", h_select[i], w_select[j]);
            //#の数を数える
            let mut black = 0;
            for x in 0..h{
                for y in 0..w{
                    if chk_board[x][y] == '#'{
                        black += 1;
                    }
                }
            }
            if black == k {
                ans += 1;
            }
            
        }
    }
    println!("{}",ans);
}

Submission Info

Submission Time
Task C - H and V
User yu2ta7ka
Language Rust (1.42.0)
Score 300
Code Size 2499 Byte
Status AC
Exec Time 8 ms
Memory 2180 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 16
Set Name Test Cases
Sample a01.txt, a02.txt, a03.txt, a04.txt
All a01.txt, a02.txt, a03.txt, a04.txt, b05.txt, b06.txt, b07.txt, b08.txt, b09.txt, b10.txt, b11.txt, b12.txt, b13.txt, b14.txt, b15.txt, b16.txt
Case Name Status Exec Time Memory
a01.txt AC 4 ms 2048 KB
a02.txt AC 2 ms 2004 KB
a03.txt AC 3 ms 2180 KB
a04.txt AC 8 ms 1968 KB
b05.txt AC 4 ms 2084 KB
b06.txt AC 4 ms 1960 KB
b07.txt AC 5 ms 2068 KB
b08.txt AC 4 ms 2092 KB
b09.txt AC 2 ms 2156 KB
b10.txt AC 5 ms 1992 KB
b11.txt AC 4 ms 1960 KB
b12.txt AC 4 ms 2140 KB
b13.txt AC 2 ms 2116 KB
b14.txt AC 2 ms 2144 KB
b15.txt AC 2 ms 2048 KB
b16.txt AC 2 ms 2024 KB