Submission details
Task:Hypyt
Sender:vulpesomnia
Submission time:2025-10-30 14:01:34 +0200
Language:Rust (2021)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.00 s1, 2, 3, 4, 5details
#20.00 s1, 2, 3, 4, 5details
#30.00 s1, 2, 3, 4, 5details
#40.00 s1, 2, 3, 4, 5details
#50.00 s1, 2, 3, 4, 5details
#6--2, 5details
#7--2, 5details
#8--2, 5details
#90.63 s3, 4, 5details
#100.73 s3, 4, 5details
#110.65 s3, 4, 5details
#120.79 s4, 5details
#130.80 s4, 5details
#140.84 s4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#190.97 s5details
#200.99 s5details
#210.95 s5details
#220.00 s1, 2, 3, 4, 5details
#230.00 s1, 2, 3, 4, 5details
#240.01 s5details
#250.31 s5details
#26--5details
#270.00 s5details

Code

use std::collections::HashMap;
use std::io;

#[derive(Clone, PartialEq, Debug)]
enum Tile {
    SAFE,
    MONSTER,
}

// max size: 250*250
#[derive(Clone, Debug)]
struct Node {
    row_index: usize,
    // row, col
    //edges: Vec<(usize, usize)>,
    edges: HashMap<usize, 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(),
    );

    // Get all indexes for each row. O(n^2)
    let mut map: Vec<Vec<Tile>> = vec![vec![Tile::MONSTER; width]; height];
    let mut indexes_per_row: Vec<usize> = vec![0; height];
    for h in 0..height {
        let mut line = String::new();
        io::stdin().read_line(&mut line).expect("failed");
        for (i, c) in line.chars().enumerate() {
            if c == '.' {
                map[h][i] = Tile::SAFE;
                indexes_per_row[h] += 1;
            }
        }
    }

    let mut graph: Vec<Node> = Vec::new();
    // Instantiate graph with nodes. O(n)
    for r in 0..height {
        if indexes_per_row[r] != 0 {
            graph.push(Node {
                row_index: r,
                edges: HashMap::new(),
            });
        }
    }

    println!("{:?}", indexes_per_row);
    // Create graph from overlapping indexes. O(n^3)
    let mut offset1 = 0;
    for r1 in 0..height {
        if indexes_per_row[r1] != 0 {
            for r2 in 0..height {
                if indexes_per_row[r2] != 0 {
                    //&& r1 != r2 {
                    for i in 0..width {
                        if map[r1][i] == Tile::SAFE {
                            if map[r1][i] == map[r2][i] {
                                graph[r1 - offset1].edges.insert(r2, i);
                            }
                        }
                    }
                }
            }
        } else {
          offset1 += 1;
        }
    }
    println!("{:?}", graph);

    // i: Row_1, j: Row_2 -> length, (shortest path starting column and ending column)
    const INF: usize = 10_usize.pow(5);
    // inside vecvec -> (length, start_cols, end_cols, pairs) MAX RAM = 156,5mb or something < 250mb
    let mut answer_map: Vec<Vec<(usize, Vec<usize>, Vec<usize>, Vec<(usize, usize)>)>> =
        vec![vec![(INF, Vec::new(), Vec::new(), Vec::new()); graph.len()]; graph.len()];

    // Creating starting matrix for answer_map. O(n^2). [Get length + all edges]
    // For example: NODE1 ->(c_1 and c_2) NODE2 = 1, (c_1, c_1) && 1, (c_2, c_2)
    for n1 in graph.clone() {
        // WARN: Clone here might have adverse effects to speed?
        for n2 in n1.edges {
            let mut length: usize = 1;
            if n1.row_index == n2.0 {
                length = 0;
            }
            // NOTE: Might have issues, since if same row then columns are set, but probably not since initial processing of
            // the queries should remove such issues.
            answer_map[n1.row_index][n2.0] = (length, vec![n2.1], vec![n2.1], vec![(n2.1, n2.1)]);
        }
    }

    // Update matrix to final form. O(n^3)
    let graph_size: usize = graph.len();
    for ni in 0..graph_size {
        for n1 in 0..graph_size {
            for n2 in 0..graph_size {
                if graph[n1].edges.contains_key(&n2)
                    && graph[n1].edges.contains_key(&ni)
                    && graph[ni].edges.contains_key(&n2)
                {
                    let sum = answer_map[n1][ni].0 + answer_map[ni][n2].0;
                    if answer_map[n1][n2].0 > sum {
                        answer_map[n1][n2].0 = sum;
                        answer_map[n1][n2].1 = vec![graph[n1].edges[&ni]];
                        answer_map[n1][n2].2 = vec![graph[ni].edges[&n2]];
                        answer_map[n1][n2].3 = vec![(graph[n1].edges[&ni], graph[ni].edges[&n2])];
                    } else {
                        answer_map[n1][n2].1.push(graph[n1].edges[&ni]);
                        answer_map[n1][n2].2.push(graph[ni].edges[&n2]);
                        answer_map[n1][n2]
                            .3
                            .push((graph[n1].edges[&ni], graph[ni].edges[&n2]));
                    }
                }
            }
        }
    }

    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 ans = &answer_map[y1 - 1][y2 - 1];
            let mut leaps = if ans.0 != INF { 2 * ans.0 - 1 } else { INF };
            println!("leaps beginning: {}", leaps);
            if leaps == INF {
                println!("{}", -1);
            } else {
                if !ans.1.contains(&(y1 - 1)) {
                    leaps += 1;
                    if !ans.2.contains(&(y2 - 1)) {
                        leaps += 1;
                    }
                } else {
                    if !ans.2.contains(&(y2 - 1)) {
                        leaps += 1;
                    } else {
                      println!("test");
                      println!("{:?}", ans.3);
                        if !ans.3.contains(&(y1 - 1, y2 - 1)) && !ans.3.contains(&(y2 - 1, y1 - 1)) {
                            leaps += 1;
                        }
                    }
                }
                println!("{}", leaps);
            }
        }
    }
}

Test details

Test 1 (public)

Group: 1, 2, 3, 4, 5

Verdict:

input
4 6 5
.*.***
*...**
*****.
*..*.*
...

correct output
1
0
3
3
-1

user output
[2, 3, 1, 3]
[Node { row_index: 0, edges: {...

Feedback: Output is longer than expected

Test 2

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
..........
.....*....
........*.
*.*....*..
...

correct output
1
2
1
2
2
...

user output
[10, 9, 9, 7, 9, 8, 6, 8, 8, 7...

Feedback: Output is longer than expected

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
*...***.**
*****.*...
**..**.**.
..**.**.*.
...

correct output
1
2
2
1
2
...

user output
[4, 4, 4, 5, 8, 5, 5, 5, 4, 3]
[Node { row_index: 0, edges: {...

Feedback: Output is longer than expected

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
***.*.****
**********
*.********
.*.***.**.
...

correct output
3
4
2
3
4
...

user output
[2, 0, 1, 4, 0, 1, 1, 3, 3, 4]
[Node { row_index: 0, edges: {...

Error:
thread 'main' panicked at input/code.rs:96:37:
index out of bounds: the len is 8 but the index is 8
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 1
.****.****
**.**..***
**********
*******..*
...

correct output
7

user output
[2, 3, 0, 2, 0, 2, 2, 0, 1, 2]
[Node { row_index: 0, edges: {...

Error:
thread 'main' panicked at input/code.rs:96:37:
index out of bounds: the len is 7 but the index is 8
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Test 6

Group: 2, 5

Verdict:

input
250 250 250
.*...*.....*******..**...*.......

correct output
2
3
3
2
2
...

user output
(empty)

Test 7

Group: 2, 5

Verdict:

input
250 250 250
...*......**.**.*.*..**..*..**...

correct output
2
2
2
2
3
...

user output
(empty)

Test 8

Group: 2, 5

Verdict:

input
250 250 250
**..**..****.****.*.***.***..*...

correct output
2
3
3
3
3
...

user output
(empty)

Test 9

Group: 3, 4, 5

Verdict:

input
40 40 200000
...*.**.*..*.............*.*.....

correct output
2
2
2
2
2
...

user output
[33, 33, 33, 32, 30, 31, 27, 3...

Feedback: Output is longer than expected

Test 10

Group: 3, 4, 5

Verdict:

input
40 40 200000
**.**..*.*.*.******....****.*....

correct output
2
1
3
2
2
...

user output
[17, 16, 20, 20, 20, 20, 24, 1...

Feedback: Output is longer than expected

Test 11

Group: 3, 4, 5

Verdict:

input
40 40 200000
.*.*.**.*****.***.*.****.**.**...

correct output
3
3
3
3
3
...

user output
[11, 7, 8, 6, 10, 13, 3, 11, 9...

Feedback: Output is longer than expected

Test 12

Group: 4, 5

Verdict:

input
80 80 200000
*....**.***..****...*.....*......

correct output
2
2
2
2
2
...

user output
[56, 55, 58, 64, 61, 54, 58, 6...

Feedback: Output is longer than expected

Test 13

Group: 4, 5

Verdict:

input
80 80 200000
.***.*..*.***..*****....**...*...

correct output
3
2
2
3
2
...

user output
[39, 36, 32, 42, 39, 32, 37, 4...

Feedback: Output is longer than expected

Test 14

Group: 4, 5

Verdict:

input
80 80 200000
*******.*****.*..*..****...***...

correct output
2
3
1
2
2
...

user output
[23, 19, 17, 19, 21, 16, 26, 1...

Feedback: Output is longer than expected

Test 15

Group: 5

Verdict:

input
250 250 200000
*....*..*..*..**..*.........**...

correct output
3
2
2
2
2
...

user output
(empty)

Test 16

Group: 5

Verdict:

input
250 250 200000
..*....*..*......*.**.*.*..***...

correct output
2
2
2
2
2
...

user output
(empty)

Test 17

Group: 5

Verdict:

input
250 250 200000
*..*.*****.*********.****.****...

correct output
3
3
2
2
2
...

user output
(empty)

Test 18

Group: 5

Verdict:

input
250 250 200000
*********.**********.******.**...

correct output
3
3
3
3
3
...

user output
(empty)

Test 19

Group: 5

Verdict:

input
250 250 200000
.*****************************...

correct output
104
422
145
93
65
...

user output
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2,...

Feedback: Output is longer than expected

Test 20

Group: 5

Verdict:

input
250 250 200000
..****************************...

correct output
57
155
38
65
98
...

user output
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4,...

Feedback: Output is longer than expected

Test 21

Group: 5

Verdict:

input
250 250 200000
.*****************************...

correct output
498
498
498
498
498
...

user output
[1, 2, 2, 2, 2, 2, 2, 2, 2, 2,...

Feedback: Output is longer than expected

Test 22

Group: 1, 2, 3, 4, 5

Verdict:

input
10 1 10
*
*
.
*
...

correct output
0
1
1
0
0
...

user output
[0, 0, 1, 0, 0, 1, 0, 0, 0, 1]
[Node { row_index: 2, edges: {...

Error:
thread 'main' panicked at input/code.rs:96:37:
index out of bounds: the len is 3 but the index is 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Test 23

Group: 1, 2, 3, 4, 5

Verdict:

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
[9]
[Node { row_index: 0, edges: {...

Feedback: Output is longer than expected

Test 24

Group: 5

Verdict:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
[0, 1, 0, 1, 1, 0, 0, 1, 0, 1,...

Error:
thread 'main' panicked at input/code.rs:96:37:
index out of bounds: the len is 130 but the index is 201
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Test 25

Group: 5

Verdict:

input
1 250 200000
*.*.*...*.*.**.***..**.*.*..**...

correct output
1
1
1
1
1
...

user output
[135]
[Node { row_index: 0, edges: {...

Feedback: Output is longer than expected

Test 26

Group: 5

Verdict:

input
250 250 200000
.................................

correct output
2
2
2
2
2
...

user output
(empty)

Test 27

Group: 5

Verdict:

input
250 250 200000
******************************...

correct output
0
0
0
0
0
...

user output
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...

Error:
thread 'main' panicked at input/code.rs:96:23:
index out of bounds: the len is 1 but the index is 249
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace