Submission details
Task:Hypyt
Sender:asonnine
Submission time:2025-10-31 23:55:59 +0200
Language:Rust (2021)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4, 5details
#2ACCEPTED0.00 s1, 2, 3, 4, 5details
#30.00 s1, 2, 3, 4, 5details
#4--1, 2, 3, 4, 5details
#5ACCEPTED0.00 s1, 2, 3, 4, 5details
#6--2, 5details
#70.95 s2, 5details
#80.56 s2, 5details
#90.43 s3, 4, 5details
#100.45 s3, 4, 5details
#110.43 s3, 4, 5details
#120.56 s4, 5details
#130.62 s4, 5details
#140.58 s4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19--5details
#200.96 s5details
#21--5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.44 s5details
#25ACCEPTED0.32 s5details
#26--5details
#27ACCEPTED0.34 s5details

Code

use std::{io, usize, vec};

#[derive(Debug, Clone)]
struct Row {
    connections: Vec<usize>,
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let (n, m, q): (usize, usize, usize) = {
        let mut iter = input.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let mut map: Vec<Vec<bool>> = Vec::new();
    for _ in 0..n {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        map.push(input.trim().chars().map(|x| x == '.').collect());
    }
    let mut rows: Vec<Row> = vec![
        Row {
            connections: Vec::new()
        };
        n
    ];
    for row in 0..n {
        for column in 0..m {
            if map[row][column] {
                for rowi in 0..n {
                    if map[rowi][column] && !rows[row].connections.contains(&rowi) && row != rowi {
                        rows[row].connections.push(rowi);
                    }
                }
            }
        }
    }

    let mut queries: Vec<((usize, usize), (usize, usize))> = Vec::new();
    for _ in 0..q {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        let (y1, x1, y2, x2): (usize, usize, usize, usize) = {
            let mut iter = input.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            )
        };
        queries.push(((x1 - 1, y1 - 1), (x2 - 1, y2 - 1)));
    }

    let rows = rows;
    let queries = queries;

    dbg!(&rows);

    for query in queries {
        println!("{}", process_query(&rows, &map, query));
    }
}

fn process_query(
    map_rows: &Vec<Row>,
    map: &Vec<Vec<bool>>,
    query: ((usize, usize), (usize, usize)),
) -> i32 {
    let mut steps = 1;
    let rows = map_rows.len();
    let mut used_rows = vec![false; rows];

    if query.0 == query.1 {
        return 0;
    } else if query.0.0 == query.1.0 || query.0.1 == query.1.1 {
        return 1;
    }

    let mut process_rows: Vec<usize> = Vec::new();

    for row in 0..rows {
        if map[row][query.0.0] {
            process_rows.push(row);
            used_rows[row] = true;
        }
    }

    let mut can_continue = false;

    loop {
        if used_rows[query.1.1] {
            return steps + 1;
        }

        let mut new_process_rows: Vec<usize> = Vec::new();

        for row in process_rows {
            for rowi in &map_rows[row].connections {
                if !used_rows[*rowi] {
                    used_rows[*rowi] = true;
                    new_process_rows.push(*rowi);
                    can_continue = true;
                    if *rowi == query.1.1 {
                        if map[row][query.1.0] {
                            return steps + 1;
                        } else {
                            return steps + 2;
                        }
                    }
                }
            }
        }

        if !can_continue {
            return -1;
        }

        process_rows = new_process_rows;

        steps += 2;
    }
}

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

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            1,
            3,
        ],
    },
    Row {
        connections: [
            3,
            0,
        ],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [
            1,
            0,
        ],
    },
]

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
...

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            1,
            2,
            4,
            5,
            6,
            7,
            8,
            9,
            3,
        ],
    },
    Row {
        connections: [
            0,
            2,
            4,
            5,
            6,
            7,
            8,
            9,
            3,
        ],
    },
    Row {
        connections: [
            0,
            1,
            4,
            5,
            6,
            7,
            8,
            9,
            3,
        ],
    },
    Row {
        connections: [
            0,
            1,
            2,
            4,
            5,
            8,
            6,
            9,
            7,
        ],
    },
    Row {
        connections: [
            0,
            1,
            2,
            5,
            6,
            7,
            8,
            9,
            3,
        ],
    },
    Row {
        connections: [...

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
1
3
2
1
2
...

Feedback: Incorrect character on line 2 col 1: expected "2", got "3"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            3,
            4,
            5,
            6,
            8,
            2,
            7,
            9,
            1,
        ],
    },
    Row {
        connections: [
            9,
            0,
            3,
            4,
            5,
            6,
            7,
            2,
        ],
    },
    Row {
        connections: [
            0,
            4,
            7,
            8,
            9,
            5,
            6,
            1,
            3,
        ],
    },
    Row {
        connections: [
            4,
            5,
            8,
            0,
            6,
            7,
            1,
            2,
            9,
        ],
    },
    Row {
        connections: [
            3,
            5,
            8,
            0,
            6,
            2,
            7,
            9,
            1,
        ],
    },
    Row {
        connections: [
            3,...

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
(empty)

Test 5

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

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

correct output
7

user output
7

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            5,
            1,
            8,
        ],
    },
    Row {
        connections: [
            0,
            8,
            9,
        ],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [
            5,
            6,
        ],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [
            0,
            3,
            6,
        ],
    },
    Row {
        connections: [
            3,
            5,
        ],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [
            0,
            1,
        ],
    },
    Row {
        connections: [
            1,
        ],
    },
]

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
2
3
2
2
2
...

Feedback: Incorrect character on line 2 col 1: expected "2", got "3"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            2,
            3,
            4,
            8,
            9,
            11,
            12,
            15,
            16,
            20,
            21,
            22,
            23,
            26,
            28,
            29,
            32,
            36,
            37,
            41,
            45,
            46,
            47,
            50,
            52,
            53,
            54,
            62,
            64,
            67,
            68,
            70,
            72,
            74,
            75,
            77,
            78,
            79,
            80,
            84,
            88,
            93,
            96,
            97,
            98,
            99,
            102,
            105,
            106,
            107,
            108,
            109,
            110,
            111,
            112,
            114,
            116,
            120,...

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
2
3
2
3
2
...

Feedback: Incorrect character on line 3 col 1: expected "3", got "2"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            4,
            18,
            22,
            25,
            26,
            27,
            31,
            34,
            39,
            45,
            55,
            59,
            60,
            71,
            76,
            86,
            88,
            90,
            94,
            99,
            103,
            107,
            108,
            118,
            121,
            123,
            126,
            127,
            135,
            144,
            150,
            154,
            157,
            163,
            168,
            174,
            178,
            180,
            181,
            184,
            186,
            189,
            194,
            196,
            202,
            204,
            209,
            217,
            220,
            223,
            229,
            236,
            237,
            246,
            247,
            2,...

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Feedback: Incorrect character on line 32 col 1: expected "3", got "2"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            12,
            13,
            14,
            15,
            16,
            18,
            19,
            22,
            23,
            24,
            25,
            26,
            27,
            28,
            29,
            30,
            32,
            33,
            34,
            35,
            36,
            37,
            39,
            1,
            11,
            20,
            31,
            21,
            38,
            17,
        ],
    },
    Row {
        connections: [
            0,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            13,
            15,
            16,
            18,
            19,
            20,...

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
2
1
3
2
2
...

Feedback: Incorrect character on line 7 col 1: expected "3", got "2"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            1,
            3,
            6,
            8,
            14,
            16,
            18,
            21,
            22,
            24,
            27,
            28,
            29,
            31,
            33,
            35,
            36,
            37,
            39,
            4,
            9,
            11,
            17,
            20,
            23,
            26,
            30,
            34,
            10,
            12,
            13,
            15,
            19,
            25,
            32,
            38,
            5,
            7,
            2,
        ],
    },
    Row {
        connections: [
            3,
            7,
            9,
            10,
            12,
            13,
            15,
            17,
            19,
            20,
            21,
            24,
            25,
            26,
            27,
            30,
            31,...

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 16 col 1: expected "3", got "2"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            4,
            11,
            18,
            19,
            36,
            38,
            1,
            5,
            13,
            14,
            16,
            21,
            22,
            26,
            34,
            37,
            2,
            6,
            7,
            9,
            17,
            29,
            35,
            8,
            12,
            28,
            32,
            20,
            27,
            31,
            3,
            23,
            25,
            10,
            15,
            30,
        ],
    },
    Row {
        connections: [
            0,
            5,
            11,
            13,
            14,
            16,
            18,
            21,
            22,
            26,
            34,
            36,
            37,
            9,
            20,
            27,
            31,
            32,
            19,
            25,...

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Feedback: Incorrect character on line 16 col 1: expected "2", got "3"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            1,
            2,
            4,
            5,
            6,
            7,
            10,
            11,
            12,
            13,
            15,
            16,
            18,
            19,
            21,
            22,
            23,
            24,
            25,
            26,
            29,
            30,
            31,
            32,
            33,
            34,
            35,
            36,
            38,
            39,
            40,
            41,
            42,
            43,
            44,
            45,
            47,
            48,
            49,
            51,
            52,
            53,
            54,
            55,
            58,
            59,
            60,
            62,
            64,
            66,
            67,
            68,
            69,
            70,
            71,
            73,
            74,
            75,
            76,...

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
3
2
2
2
2
...

Feedback: Incorrect character on line 4 col 1: expected "3", got "2"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            1,
            2,
            5,
            7,
            8,
            17,
            19,
            20,
            22,
            26,
            27,
            30,
            31,
            35,
            37,
            39,
            40,
            41,
            42,
            44,
            45,
            47,
            49,
            50,
            51,
            56,
            58,
            59,
            62,
            63,
            64,
            67,
            70,
            75,
            77,
            6,
            9,
            10,
            13,
            15,
            16,
            21,
            23,
            24,
            28,
            29,
            36,
            38,
            46,
            55,
            60,
            61,
            65,
            68,
            71,
            72,
            76,
            79,
            3,...

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
2
3
1
2
3
...

Feedback: Incorrect character on line 5 col 1: expected "2", got "3"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            3,
            6,
            7,
            9,
            10,
            12,
            13,
            15,
            16,
            18,
            22,
            30,
            33,
            39,
            47,
            48,
            50,
            51,
            53,
            55,
            58,
            59,
            61,
            63,
            72,
            78,
            79,
            19,
            20,
            24,
            27,
            28,
            36,
            37,
            41,
            42,
            52,
            70,
            73,
            75,
            1,
            4,
            11,
            26,
            32,
            35,
            45,
            46,
            56,
            57,
            76,
            5,
            43,
            2,
            23,
            60,
            62,
            66,
            69,...

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
(empty)

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
57
154
38
64
98
...

Feedback: Incorrect character on line 2 col 3: expected "155", got "154"
Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [
            1,
            248,
            249,
        ],
    },
    Row {
        connections: [
            0,
            248,
            249,
        ],
    },
    Row {
        connections: [
            3,
            248,
            249,
            246,
            247,
        ],
    },
    Row {
        connections: [
            2,
            248,
            249,
            246,
            247,
        ],
    },
    Row {
        connections: [
            5,
            246,
            247,
            244,
            245,
        ],
    },
    Row {
        connections: [
            4,
            246,
            247,
            244,
            245,
        ],
    },
    Row {
        connections: [
            7,
            244,
            245,
            242,
            243,
        ],
    },
    Row {
        connections: [
            6,
            244,
            245,
            242,...

Test 21

Group: 5

Verdict:

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
...

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [
            5,
            9,
        ],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [
            2,
            9,
        ],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [
            2,
            5,
        ],
    },
]

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
...

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [],
    },
]

Test 24

Group: 5

Verdict: ACCEPTED

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [],
    },
    Row {
        connections: [
            3,
            4,
            7,
            9,
            13,
            14,
            17,
            18,
            22,
            25,
            30,
            31,
            32,
            34,
            35,
            36,
            41,
            42,
            43,
            45,
            46,
            47,
            48,
            50,
            52,
            57,
            61,
            64,
            67,
            68,
            69,
            70,
            71,
            72,
            75,
            76,
            77,
            78,
            81,
            83,
            84,
            85,
            86,
            87,
            88,
            91,
            92,
            93,
            94,
            96,
            97,
            98,
            100,
            103,
            106,
            107,...

Test 25

Group: 5

Verdict: ACCEPTED

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

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [],
    },
]

Test 26

Group: 5

Verdict:

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
...

Error:
[input/code.rs:62] &rows = [
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    Row {
        connections: [],
    },
    R...