結果

問題 No.640 76本のトロンボーン
ユーザー phsplsphspls
提出日時 2023-01-17 00:10:56
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,166 bytes
コンパイル時間 3,378 ms
コンパイル使用メモリ 148,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 05:50:46
合計ジャッジ時間 2,454 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let grid = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.chars().collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let mut result = 0usize;
    for dir in 0..2 {
        for is_w in 0..2 {
            let mut grid = grid.clone();
            let mut temp = 0usize;
            if is_w == 1 {
                for i in 0..n {
                    let cnt = (0..n).filter(|&j| grid[i][j] == '#').count();
                    if cnt > 1 { continue; }
                    if dir == 0 {
                        if cnt == 0 || grid[i][0] == '#' {
                            (1..n).for_each(|j| grid[i][j] = '#');
                            temp += 1;
                        } else if grid[i][n-1] == '#' {
                            (0..n-1).for_each(|j| grid[i][j] = '#');
                            temp += 1;
                        }
                    } else {
                        if cnt == 0 || grid[i][n-1] == '#' {
                            (0..n-1).for_each(|j| grid[i][j] = '#');
                            temp += 1;
                        } else if grid[i][0] == '#' {
                            (1..n).for_each(|j| grid[i][j] = '#');
                            temp += 1;
                        }
                    }
                }
                let cnt = (0..n).filter(|&i| grid[i][n-1] == '#').count();
                if cnt == 0 {
                    temp += 1;
                } else if cnt == 1 && (grid[0][n-1] == '#' || grid[n-1][n-1] == '#') {
                    temp += 1;
                }
            } else {
                for j in 0..n {
                    let cnt = (0..n).filter(|&i| grid[i][j] == '#').count();
                    if cnt > 1 { continue; }
                    if dir == 0 {
                        if cnt == 0 || grid[0][j] == '#' {
                            (1..n).for_each(|i| grid[i][j] = '#');
                            temp += 1;
                        } else if grid[n-1][j] == '#' {
                            (0..n-1).for_each(|i| grid[i][j] = '#');
                            temp += 1;
                        }
                    } else {
                        if cnt == 0 || grid[n-1][j] == '#' {
                            (0..n-1).for_each(|i| grid[i][j] = '#');
                            temp += 1;
                        } else if grid[0][j] == '#' {
                            (1..n).for_each(|i| grid[i][j] = '#');
                            temp += 1;
                        }
                    }
                }
                let cnt = (0..n).filter(|&j| grid[n-1][j] == '#').count();
                if cnt == 0 {
                    temp += 1;
                } else if cnt == 1 && (grid[n-1][0] == '#' || grid[n-1][n-1] == '#') {
                    temp += 1;
                }
            }
            result = result.max(temp);
        }
    }
    println!("{}", result);
}
0