Submission details
Task:Hypyt
Sender:asonnine
Submission time:2025-10-31 13:48:21 +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
#60.09 s2, 5details
#70.08 s2, 5details
#80.05 s2, 5details
#90.49 s3, 4, 5details
#100.64 s3, 4, 5details
#110.72 s3, 4, 5details
#120.96 s4, 5details
#13--4, 5details
#14--4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19--5details
#20--5details
#210.32 s5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.32 s5details
#25ACCEPTED0.33 s5details
#260.55 s5details
#27ACCEPTED0.32 s5details

Code

use std::{io, vec};

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

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![false; n]
        };
        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[rowi] = true;
                    }
                }
            }
        }
    }

    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;

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

// NOTE: Needs to be O(n+m)
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.1.0 == query.1.1 {
        return 1;
    }

    let mut process_rows = vec![false; rows];

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

    let mut can_continue = false;

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

        for row in 0..rows {
            if process_rows[row] {
                process_rows[row] = false;
                for row in 0..rows {
                    if map_rows[row].connections[row] {
                        if !used_rows[row] {
                            used_rows[row] = true;
                            process_rows[row] = true;
                            can_continue = true
                        }
                    }
                }
            }
        }

        if !can_continue {
            return -1;
        }

        steps += 2;
    }
}

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
1
0
3
3
1

Feedback: Incorrect character on line 5 col 1: expected "-1", got "1"

Test 2

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
1
2
2
...

user output
1
1
1
3
3
...

Feedback: Incorrect character on line 2 col 1: expected "2", got "1"

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
1
3
3
1
1
...

Feedback: Incorrect character on line 2 col 1: expected "2", got "3"

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
3
1
1
3
3
...

Feedback: Incorrect character on line 2 col 1: expected "4", got "1"

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
7

user output
3

Feedback: Incorrect character on line 1 col 1: expected "7", got "3"

Test 6

Group: 2, 5

Verdict:

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

correct output
2
3
3
2
2
...

user output
1
3
3
3
3
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 7

Group: 2, 5

Verdict:

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

correct output
2
2
2
2
3
...

user output
3
3
1
1
3
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "3"

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
1
3
3
3
3
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
1
3
1
3
1
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
1
1
3
1
1
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
3
3
3
1
3
...

Feedback: Incorrect character on line 4 col 1: expected "3", got "1"

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
1
3
1
1
1
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
(empty)

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
(empty)

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

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
1
1
1
1
1
...

Feedback: Incorrect character on line 1 col 1: expected "498", got "1"

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:

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

correct output
2
2
2
2
2
...

user output
1
1
1
1
1
...

Feedback: Incorrect character on line 1 col 1: expected "2", got "1"

Test 27

Group: 5

Verdict: ACCEPTED

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

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...