| Task: | Hypyt |
| Sender: | vulpesomnia |
| Submission time: | 2025-11-05 09:33:01 +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 | ACCEPTED | 0.66 s | 2, 5 | details |
| #8 | ACCEPTED | 0.22 s | 2, 5 | details |
| #9 | ACCEPTED | 0.97 s | 3, 4, 5 | details |
| #10 | ACCEPTED | 0.96 s | 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 | ACCEPTED | 0.32 s | 5 | details |
| #25 | ACCEPTED | 0.31 s | 5 | details |
| #26 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #27 | ACCEPTED | 0.33 s | 5 | details |
Compiler report
warning: function `print_map` is never used
--> input/code.rs:191:4
|
191 | fn print_map(map: &Vec<Node>) {
| ^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: 1 warning emittedCode
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::cmp::min;
use std::io;
#[derive(Clone, PartialEq, Debug)]
enum Tile {
SAFE,
MONSTER,
}
struct Node {
_id: usize,
// usize on id of node(row) ja hashset on sarakkeet.
edges: HashMap<usize, HashSet<usize>>,
}
fn main() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("failed to readline");
let mut iter = input.trim().split_whitespace();
let (height, width, query_count): (usize, usize, i32) = (
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
);
let mut graph: Vec<Node> = Vec::new();
// Get all indexes for each row. O(n^2)
let mut map: Vec<Vec<Tile>> = vec![vec![Tile::MONSTER; width]; height];
for h in 0..height {
let mut line = String::new();
io::stdin().read_line(&mut line).expect("failed");
graph.push(Node {
_id: h,
edges: HashMap::new(),
});
for (i, c) in line.chars().enumerate() {
if c == '.' {
map[h][i] = Tile::SAFE;
}
}
}
//const INF: usize = 10_usize.pow(5);
// Create graph from overlapping indexes. O(n^3)
for r1 in 0..height {
for r2 in 0..height {
if r1 != r2 {
for i in 0..width {
if map[r1][i] == Tile::SAFE && map[r1][i] == map[r2][i] {
if !graph[r1].edges.contains_key(&r2) {
let mut set = HashSet::new();
set.insert(i);
graph[r1].edges.insert(r2, set);
} else {
if let Some(val) = graph[r1].edges.get_mut(&r2) {
val.insert(i);
};
}
}
}
}
}
}
//print_map(&graph);
for _ in 0..query_count {
let mut query = String::new();
io::stdin()
.read_line(&mut query)
.expect("failed to readline");
let mut iter = query.trim().split_whitespace();
let (y1, x1, y2, x2): (usize, usize, usize, usize) = (
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
);
if x1 == x2 && y1 == y2 {
println!("{}", 0);
} else if x1 == x2 || y1 == y2 {
println!("{}", 1);
} else {
let mut depth = 0;
let mut leaps = 2000;
// Then use BFS:
let mut queue: VecDeque<(usize, &HashSet<usize>)> = VecDeque::new();
let mut explored_nodes: HashSet<usize> = HashSet::new();
let root_node = y1 - 1;
let target_node = y2 - 1;
let mut found_target = false;
explored_nodes.insert(root_node);
let dummy: HashSet<usize> = HashSet::new();
queue.push_front((root_node, &dummy));
while queue.len() != 0 {
depth += 1;
let mut level_size = queue.len();
/*println!("# - - - - - #");
println!("DEPTH: {:?}", depth);
println!("QUEUE: {:?} WHICH IS LEN: {:?}", queue, level_size);
println!("# - - - - - #");*/
while level_size > 0 {
let current: (usize, &HashSet<usize>) = *queue.front().unwrap();
// println!("CURRENT: {:?}", current);
queue.pop_front();
for adj_node in &graph[current.0].edges {
// If it is target_node.
if *adj_node.0 == target_node {
/* println!("THIS IS TARGET:");
println!("Adjacent node: {:?}", adj_node);*/
found_target = true;
let end_column = adj_node.1.contains(&(x2 - 1));
/* println!("END_COLUMNS: {:?} ", adj_node.1);
println!("END_COLUMN: {}", end_column);*/
if depth == 1 {
let start_column = graph[*adj_node.0].edges[¤t.0].contains(&(x1 - 1));
/* println!("START_COLUMNS: {:?} ", graph[*adj_node.0].edges[¤t.0]);
println!("START_COLUMN: {}", start_column);*/
if start_column && end_column { // handle specific edgecase
//println!("TEEEST, this shouldnt happen?");
if x2 - 1 == x1 - 1 {
leaps = 0;
} else {
leaps = 1;
}
} else {
set_leaps(start_column, end_column, &mut leaps);
}
} else {
let start_column = current.1.contains(&(x1 - 1));
/*println!("START_COLUMNS: {:?} ", current.1);
println!("START_COLUMN: {}", start_column);*/
set_leaps(start_column, end_column, &mut leaps);
}
} else if !explored_nodes.contains(&adj_node.0) {
//println!("Adjacent node: {:?}", adj_node);
explored_nodes.insert(*adj_node.0);
if current.0 == root_node {
queue.push_front((*adj_node.0, adj_node.1));
} else {
queue.push_back((*adj_node.0, current.1));
}
}
}
level_size -= 1;
}
if found_target {
/* println!("FOUND TARGET! LEAPS: {:?}", leaps);
println!("queue after: {:?}", queue);*/
break;
}
}
if !found_target {
println!("{}", -1);
} else {
if leaps == 2000 { //emt miks tää mut trust
leaps = 0;
}
println!("{}", leaps + 2 * depth - 1);
}
//bfs(graph, queue, explored_nodes);
}
}
// add parameters: length, starting cols, end cols.
}
fn set_leaps(start_column: bool, end_column: bool, leaps: &mut usize) {
if start_column && !end_column {
*leaps = min(*leaps, 1);
} else if !start_column && end_column {
*leaps = min(*leaps, 1);
} else if !start_column && !end_column {
*leaps = min(*leaps, 2);
} else {
*leaps = min(*leaps, 0);
}
}
fn print_map(map: &Vec<Node>) {
println!("Node and its edges:");
let size = map.len();
for i in 0..size {
let mut line = String::new();
line.push_str(format!("{:?}", map[i].edges).as_str());
/*line.push_str("(");
for j in 0..size {
line.push_str(map[i].edges[j]);
line.push_str(" ");
}*/
line.push_str(")");
println!("{}", line);
}
println!("END!");
/*println!("Map for how many columns from starting to end row, but at the end:");
for i in 0..size {
let mut line = String::new();
for j in 0..size {
let size2 = map[i][j].1.len();
line.push_str("( ");
for c in 0..size2 {
line.push_str(map[i][j].1[c]1.to_string().as_str());
line.push_str(" ");
}
line.push_str(" )");
}
println!("{}", line);
}*/
}
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: ACCEPTED
| input |
|---|
| 250 250 250 ...*......**.**.*.*..**..*..**... |
| correct output |
|---|
| 2 2 2 2 3 ... |
| user output |
|---|
| 2 2 2 2 3 ... |
Test 8
Group: 2, 5
Verdict: ACCEPTED
| input |
|---|
| 250 250 250 **..**..****.****.*.***.***..*... |
| correct output |
|---|
| 2 3 3 3 3 ... |
| user output |
|---|
| 2 3 3 3 3 ... |
Test 9
Group: 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 40 40 200000 ...*.**.*..*.............*.*..... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| 2 2 2 2 2 ... |
Test 10
Group: 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 40 40 200000 **.**..*.*.*.******....****.*.... |
| correct output |
|---|
| 2 1 3 2 2 ... |
| user output |
|---|
| 2 1 3 2 2 ... |
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: ACCEPTED
| input |
|---|
| 250 1 200000 * . * . ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
Test 25
Group: 5
Verdict: ACCEPTED
| input |
|---|
| 1 250 200000 *.*.*...*.*.**.***..**.*.*..**... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
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 ... |
