Task: | Sokkelo |
Sender: | xnor |
Submission time: | 2022-01-22 13:54:13 +0200 |
Language: | Rust |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | RUNTIME ERROR | 0 |
#2 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#2 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#3 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#4 | RUNTIME ERROR | 0.01 s | 2 | details |
#5 | RUNTIME ERROR | 0.01 s | 2 | details |
#6 | RUNTIME ERROR | 0.01 s | 2 | details |
#7 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#8 | RUNTIME ERROR | 0.01 s | 2 | details |
#9 | RUNTIME ERROR | 0.01 s | 2 | details |
#10 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#11 | RUNTIME ERROR | 0.01 s | 2 | details |
#12 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#13 | RUNTIME ERROR | 0.01 s | 2 | details |
#14 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#15 | RUNTIME ERROR | 0.01 s | 2 | details |
#16 | RUNTIME ERROR | 0.01 s | 2 | details |
#17 | RUNTIME ERROR | 0.01 s | 2 | details |
Code
use std::{ collections::HashSet, io::{stdin, BufRead, BufReader}, }; fn main() { let mut stdin = BufReader::new(stdin()); let mut cur_line = String::new(); stdin.read_line(&mut cur_line).unwrap(); let mut nums = cur_line .split_whitespace() .map(|s| s.parse::<usize>().unwrap()); let n = nums.next().unwrap(); let m = nums.next().unwrap(); let maze = fill_maze(n, m); println!("{}", get_dist(maze, n, m)); } fn get_dist(mut maze: Vec<Vec<u8>>, n: usize, m: usize) -> usize { let mut neighbors_a = HashSet::new(); for y in 1..n - 1 { for x in 1..m - 1 { if maze[y][x] == b'A' { if y - 1 > 0 && maze[y - 1][x] != b'A' { neighbors_a.insert((x, y - 1)); } if y + 1 < n - 1 && maze[y + 1][x] != b'A' { neighbors_a.insert((x, y + 1)); } if x - 1 > 0 && maze[y][x - 1] != b'A' { neighbors_a.insert((x - 1, y)); } if x + 1 < m - 1 && maze[y][x + 1] != b'A' { neighbors_a.insert((x + 1, y)); } } } } for c in 1.. { let mut new_neighbors = HashSet::new(); for &(x, y) in &neighbors_a { if maze[y][x] == b'B' { return c; } maze[y][x] = b'A'; if y - 1 > 0 && maze[y - 1][x] != b'A' { new_neighbors.insert((x, y - 1)); } if y + 1 < n - 1 && maze[y + 1][x] != b'A' { new_neighbors.insert((x, y + 1)); } if x - 1 > 0 && maze[y][x - 1] != b'A' { new_neighbors.insert((x - 1, y)); } if x + 1 < m - 1 && maze[y][x + 1] != b'A' { new_neighbors.insert((x + 1, y)); } } neighbors_a = new_neighbors; } 0 } fn fill_maze(n: usize, m: usize) -> Vec<Vec<u8>> { let mut stdin = BufReader::new(stdin()); let mut maze = Vec::with_capacity(n); for _ in 0..n { let mut cur_line = String::new(); stdin.read_line(&mut cur_line).unwrap(); maze.push(cur_line.into_bytes()); } let mut neighbors_a = HashSet::new(); let mut neighbors_b = HashSet::new(); for y in 0..n { for x in 0..m { if maze[y][x] == b'A' { if maze[y - 1][x] == b'.' { neighbors_a.insert((x, y - 1)); } if maze[y + 1][x] == b'.' { neighbors_a.insert((x, y + 1)); } if maze[y][x - 1] == b'.' { neighbors_a.insert((x - 1, y)); } if maze[y][x + 1] == b'.' { neighbors_a.insert((x + 1, y)); } } if maze[y][x] == b'B' { if maze[y - 1][x] == b'.' { neighbors_b.insert((x, y - 1)); } if maze[y + 1][x] == b'.' { neighbors_b.insert((x, y + 1)); } if maze[y][x - 1] == b'.' { neighbors_b.insert((x - 1, y)); } if maze[y][x + 1] == b'.' { neighbors_b.insert((x + 1, y)); } } } } loop { let mut new_neighbors_a = HashSet::new(); let mut new_neighbors_b = HashSet::new(); for &(x, y) in &neighbors_a { maze[y][x] = b'A'; if maze[y - 1][x] == b'.' && !neighbors_a.contains(&(x, y - 1)) { new_neighbors_a.insert((x, y - 1)); } if maze[y + 1][x] == b'.' && !neighbors_a.contains(&(x, y + 1)) { new_neighbors_a.insert((x, y + 1)); } if maze[y][x - 1] == b'.' && !neighbors_a.contains(&(x - 1, y)) { new_neighbors_a.insert((x - 1, y)); } if maze[y][x + 1] == b'.' && !neighbors_a.contains(&(x + 1, y)) { new_neighbors_a.insert((x + 1, y)); } } for &(x, y) in &neighbors_b { maze[y][x] = b'B'; if maze[y - 1][x] == b'.' && !neighbors_b.contains(&(x, y - 1)) { new_neighbors_b.insert((x, y - 1)); } if maze[y + 1][x] == b'.' && !neighbors_b.contains(&(x, y + 1)) { new_neighbors_b.insert((x, y + 1)); } if maze[y][x - 1] == b'.' && !neighbors_b.contains(&(x - 1, y)) { new_neighbors_b.insert((x - 1, y)); } if maze[y][x + 1] == b'.' && !neighbors_b.contains(&(x + 1, y)) { new_neighbors_b.insert((x + 1, y)); } } if new_neighbors_a.is_empty() && new_neighbors_b.is_empty() { break maze; } neighbors_a = new_neighbors_a; neighbors_b = new_neighbors_b; } }
Test details
Test 1
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 2
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
2 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 3
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
9 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 4
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
1 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 5
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 6
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
335 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 7
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
20 20 #################### #####.############## ###.....############ ##.......########### ... |
correct output |
---|
10 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 8
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
436 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 9
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 10
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
20 20 #################### #B................## #################.## #################.## ... |
correct output |
---|
2 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 11
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 12
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
2 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 13
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 14
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
12 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 15
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 1000 ##############################... |
correct output |
---|
502 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 827 but the index is 827', inpu...
Test 16
Group: 2
Verdict: RUNTIME ERROR
input |
---|
3 1000 ##############################... |
correct output |
---|
1 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...
Test 17
Group: 2
Verdict: RUNTIME ERROR
input |
---|
1000 3 ### #A# #.# #.# ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Error:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', input/co...