結果
問題 | No.640 76本のトロンボーン |
ユーザー | phspls |
提出日時 | 2023-01-17 00:53:17 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,402 bytes |
コンパイル時間 | 13,877 ms |
コンパイル使用メモリ | 387,668 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-10 06:52:41 |
合計ジャッジ時間 | 13,346 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,944 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,940 KB |
ソースコード
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; if !(0..n).any(|i| grid[0][i] == '#' || grid[n-1][i] == '#' || grid[i][0] == '#' || grid[i][n-1] == '#') { result = 4; } 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 j = if dir == 0 { 0 } else { n-1 }; let cnt = (0..n).filter(|&i| grid[i][j] == '#').count(); if cnt == 0 { temp += 1; } else if cnt == 1 && (grid[0][j] == '#' || grid[n-1][j] == '#') { 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 i = if dir == 0 { 0 } else { n-1 }; let cnt = (0..n).filter(|&j| grid[i][j] == '#').count(); if cnt == 0 { temp += 1; } else if cnt == 1 && (grid[i][0] == '#' || grid[i][n-1] == '#') { temp += 1; } } result = result.max(temp); } } println!("{}", result); }