| Task: | Hypyt |
| Sender: | MatoCSES |
| Submission time: | 2025-11-04 09:20:59 +0200 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | 10 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | TIME LIMIT EXCEEDED | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| #4 | TIME LIMIT EXCEEDED | 0 |
| #5 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #2 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #3 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #4 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #6 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #7 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #8 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #14 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #17 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #18 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #19 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #20 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #21 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #22 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #23 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #24 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #25 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #26 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #27 | ACCEPTED | 0.35 s | 5 | details |
Code
use std::io::{
self,
BufRead,
BufReader
};
use std::collections::{
HashMap,
VecDeque
};
fn main() {
let mut reader: BufReader<io::Stdin> = BufReader::new(io::stdin());
let mut input: String = String::new();
reader.read_line(&mut input).unwrap();
let input: Vec<usize> = input.trim().split(" ").map(|s: &str| s.parse::<usize>().unwrap()).collect();
let graph: HashMap<(usize, usize), Vec<(usize, usize)>> = parse_graph(&input, &mut reader);
for _ in 0..input[2] {
let mut question: String = String::new();
reader.read_line(&mut question).unwrap();
let question: Vec<usize> = question.trim().split(" ").map(|s| s.parse::<usize>().unwrap()).collect();
println!("{}", calculate_path((question[0], question[1]), (question[2], question[3]), &graph));
}
}
fn parse_graph(input: &Vec<usize>, reader: &mut BufReader<io::Stdin>) -> HashMap<(usize, usize), Vec<(usize, usize)>> {
let mut graph: HashMap<(usize, usize), Vec<(usize, usize)>> = HashMap::new();
let mut row_map: HashMap<usize, Vec<usize>> = HashMap::new();
let mut col_map: HashMap<usize, Vec<usize>> = HashMap::new();
for r in 0..input[0] {
let mut row: String = String::new();
reader.read_line(&mut row).unwrap();
let row: Vec<_> = row.match_indices(".").collect();
for node in row {
let pos: (usize, usize) = (r + 1, node.0 + 1);
graph.insert(pos, Vec::new());
row_map.entry(pos.0).and_modify(|columns| columns.push(pos.1)).or_insert(Vec::from([pos.1]));
col_map.entry(pos.1).and_modify(|rows| rows.push(pos.0)).or_insert(Vec::from([pos.0]));
}
}
get_neighbours(row_map, col_map, &mut graph);
return graph;
}
fn get_neighbours(row_map: HashMap<usize, Vec<usize>>, col_map: HashMap<usize, Vec<usize>>, graph: &mut HashMap<(usize, usize), Vec<(usize, usize)>>) {
for (pos, neighbours) in graph {
for c in row_map.get(&pos.0).unwrap() {
let neighbour: (usize, usize) = (pos.0, *c);
if &neighbour != pos {
neighbours.push(neighbour);
}
}
for r in col_map.get(&pos.1).unwrap() {
let neighbour: (usize, usize) = (*r, pos.1);
if &neighbour != pos {
neighbours.push(neighbour);
}
}
}
}
fn calculate_path(start: (usize, usize), goal: (usize, usize), graph: &HashMap<(usize, usize), Vec<(usize, usize)>>) -> i32 {
let mut dist: HashMap<(usize, usize), i32> = HashMap::from([(start, 0)]);
let mut visit_queue: VecDeque<(usize, usize)> = VecDeque::from([start]);
while visit_queue.len() > 0 {
let current: (usize, usize) = visit_queue.pop_front().unwrap();
if current == goal {
return *dist.get(¤t).unwrap();
}
for neighbour in graph.get(¤t).unwrap() {
if !dist.contains_key(neighbour) {
dist.insert(*neighbour, dist.get(¤t).unwrap() + 1);
visit_queue.push_back(*neighbour);
}
}
}
return -1;
}Test details
Test 1 (public)
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 4 6 5 .*.*** *...** *****. *..*.* ... |
| correct output |
|---|
| 1 0 3 3 -1 |
| user output |
|---|
| 1 0 3 3 -1 |
Test 2
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 10 .......... .....*.... ........*. *.*....*.. ... |
| correct output |
|---|
| 1 2 1 2 2 ... |
| user output |
|---|
| 1 2 1 2 2 ... |
Test 3
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 10 *...***.** *****.*... **..**.**. ..**.**.*. ... |
| correct output |
|---|
| 1 2 2 1 2 ... |
| user output |
|---|
| 1 2 2 1 2 ... |
Test 4
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 10 ***.*.**** ********** *.******** .*.***.**. ... |
| correct output |
|---|
| 3 4 2 3 4 ... |
| user output |
|---|
| 3 4 2 3 4 ... |
Test 5
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 1 .****.**** **.**..*** ********** *******..* ... |
| correct output |
|---|
| 7 |
| user output |
|---|
| 7 |
Test 6
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 .*...*.....*******..**...*....... |
| correct output |
|---|
| 2 3 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 7
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 ...*......**.**.*.*..**..*..**... |
| correct output |
|---|
| 2 2 2 2 3 ... |
| user output |
|---|
| (empty) |
Test 8
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 **..**..****.****.*.***.***..*... |
| correct output |
|---|
| 2 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 9
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 ...*.**.*..*.............*.*..... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 10
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 **.**..*.*.*.******....****.*.... |
| correct output |
|---|
| 2 1 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 11
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 .*.*.**.*****.***.*.****.**.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 12
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *....**.***..****...*.....*...... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 13
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 .***.*..*.***..*****....**...*... |
| correct output |
|---|
| 3 2 2 3 2 ... |
| user output |
|---|
| (empty) |
Test 14
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *******.*****.*..*..****...***... |
| correct output |
|---|
| 2 3 1 2 2 ... |
| user output |
|---|
| (empty) |
Test 15
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *....*..*..*..**..*.........**... |
| correct output |
|---|
| 3 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 16
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..*....*..*......*.**.*.*..***... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 17
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *..*.*****.*********.****.****... |
| correct output |
|---|
| 3 3 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 18
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *********.**********.******.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 19
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 104 422 145 93 65 ... |
| user output |
|---|
| (empty) |
Test 20
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..****************************... |
| correct output |
|---|
| 57 155 38 65 98 ... |
| user output |
|---|
| (empty) |
Test 21
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 498 498 498 498 498 ... |
| user output |
|---|
| (empty) |
Test 22
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 1 10 * * . * ... |
| correct output |
|---|
| 0 1 1 0 0 ... |
| user output |
|---|
| 0 1 1 0 0 ... |
Test 23
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 1 10 10 ........*. 1 7 1 10 1 4 1 7 1 5 1 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
Test 24
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 1 200000 * . * . ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 25
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1 250 200000 *.*.*...*.*.**.***..**.*.*..**... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 26
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ................................. |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 27
Group: 5
Verdict: ACCEPTED
| input |
|---|
| 250 250 200000 ******************************... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| 0 0 0 0 0 ... |
