結果

問題 No.640 76本のトロンボーン
ユーザー hatoohatoo
提出日時 2018-01-27 00:10:05
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 6,289 bytes
コンパイル時間 13,600 ms
コンパイル使用メモリ 377,916 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-08 16:14:23
合計ジャッジ時間 14,615 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 *  _           _                 __                            _   _ _   _                                 _                    _                  _
 * | |         | |               / /                           | | (_) | (_)                               | |                  (_)                | |
 * | |__   __ _| |_ ___   ___   / /__ ___  _ __ ___  _ __   ___| |_ _| |_ ___   _____ ______ _ __ _   _ ___| |_ ______ ___ _ __  _ _ __  _ __   ___| |_ ___
 * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __|
 * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) |  __/ |_| | |_| |\ V /  __/      | |  | |_| \__ \ |_       \__ \ | | | | |_) | |_) |  __/ |_\__ \
 * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___|      |_|   \__,_|___/\__|      |___/_| |_|_| .__/| .__/ \___|\__|___/
 *                                                  | |                                                                           | |   | |
 *                                                  |_|                                                                           |_|   |_|
 *
 * https://github.com/hatoo/competitive-rust-snippets
 */
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

fn yoko(grid: &[Vec<bool>]) -> usize {
    let n = grid.len();
    grid.iter()
        .filter(|v| v[0..n - 1].iter().all(|&b| !b) || v[1..].iter().all(|&b| !b))
        .count()
}

fn tate(grid: &[Vec<bool>]) -> usize {
    let n = grid.len();
    (0..n)
        .filter(|&i| (0..n - 1).all(|j| !grid[j][i]) || (1..n).all(|j| !grid[j][i]))
        .count()
}

fn main() {
    let n = get!(usize);
    let mut grid: Vec<Vec<bool>> = (0..n)
        .map(|_| util::line().chars().map(|c| c == '#').collect())
        .collect();

    let sum = grid.iter()
        .map(|l| l.iter().filter(|&&b| b).count())
        .sum::<usize>();

    if sum == 0
        || (sum == 1 && (grid[0][0] || grid[0][n - 1] || grid[n - 1][0] || grid[n - 1][n - 1]))
    {
        println!("{}", n + 1);
        return;
    }

    // yoko
    let mut ans = yoko(&grid);
    if (0..n - 1).all(|i| !grid[i][0]) {
        for i in 0..n - 1 {
            grid[i][0] = true;
        }
        ans = max(ans, 1 + yoko(&grid));
        for i in 0..n - 1 {
            grid[i][0] = false;
        }
    }
    if (0..n - 1).all(|i| !grid[i][n - 1]) {
        for i in 0..n - 1 {
            grid[i][n - 1] = true;
        }
        ans = max(ans, 1 + yoko(&grid));
        for i in 0..n - 1 {
            grid[i][n - 1] = false;
        }
    }
    if (1..n).all(|i| !grid[i][0]) {
        for i in 1..n {
            grid[i][0] = true;
        }
        ans = max(ans, 1 + yoko(&grid));
        for i in 1..n {
            grid[i][0] = false;
        }
    }
    if (1..n).all(|i| !grid[i][n - 1]) {
        for i in 1..n {
            grid[i][n - 1] = true;
        }
        ans = max(ans, 1 + yoko(&grid));
        for i in 1..n {
            grid[i][n - 1] = false;
        }
    }
    // tate
    ans = max(ans, tate(&grid));
    if grid[0][..n - 1].iter().all(|&b| !b) {
        for b in &mut grid[0][..n - 1] {
            *b = true;
        }
        ans = max(ans, 1 + tate(&grid));
        for b in &mut grid[0][..n - 1] {
            *b = false;
        }
    }
    if grid[0][1..n].iter().all(|&b| !b) {
        for b in &mut grid[0][1..n] {
            *b = true;
        }
        ans = max(ans, 1 + tate(&grid));
        for b in &mut grid[0][1..n] {
            *b = false;
        }
    }
    if grid[n - 1][..n - 1].iter().all(|&b| !b) {
        for b in &mut grid[n - 1][..n - 1] {
            *b = true;
        }
        ans = max(ans, 1 + tate(&grid));
        for b in &mut grid[n - 1][..n - 1] {
            *b = false;
        }
    }
    if grid[n - 1][1..n].iter().all(|&b| !b) {
        for b in &mut grid[n - 1][1..n] {
            *b = true;
        }
        ans = max(ans, 1 + tate(&grid));
        for b in &mut grid[n - 1][1..n] {
            *b = false;
        }
    }

    println!("{}", ans);
}
0