/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ 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() -> Vec where ::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: 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]) -> 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]) -> 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> = (0..n) .map(|_| util::line().chars().map(|c| c == '#').collect()) .collect(); let mut ans = yoko(&grid); { let mut c = 0; if (0..n - 1).all(|i| !grid[i][0]) { c += 1; } if (1..n).all(|i| !grid[i][n - 1]) { c += 1; } if grid[n - 1][..n - 1].iter().all(|&b| !b) { c += 1; } if grid[0][1..n].iter().all(|&b| !b) { c += 1; } ans = max(ans, c); } { let mut c = 0; if grid[0][..n - 1].iter().all(|&b| !b) { c += 1; } if grid[n - 1][1..].iter().all(|&b| !b) { c += 1; } if (1..n).all(|i| !grid[i][0]) { c += 1; } if (0..n - 1).all(|i| !grid[i][n - 1]) { c += 1; } ans = max(ans, c); } // 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); }