結果
問題 | No.640 76本のトロンボーン |
ユーザー | hatoo |
提出日時 | 2018-01-27 00:31:16 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 6,762 bytes |
コンパイル時間 | 29,394 ms |
コンパイル使用メモリ | 377,692 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-20 17:22:11 |
合計ジャッジ時間 | 14,666 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,812 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | AC | 1 ms
6,944 KB |
ソースコード
/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ 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 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 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); }