Submission details
Task:Hypyt
Sender:20mins
Submission time:2025-11-08 20:11:54 +0200
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.13 s1, 2, 3, 4, 5details
#20.15 s1, 2, 3, 4, 5details
#30.14 s1, 2, 3, 4, 5details
#40.14 s1, 2, 3, 4, 5details
#5ACCEPTED0.14 s1, 2, 3, 4, 5details
#60.46 s2, 5details
#70.41 s2, 5details
#80.35 s2, 5details
#9--3, 4, 5details
#10--3, 4, 5details
#11--3, 4, 5details
#12--4, 5details
#13--4, 5details
#14--4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19--5details
#20--5details
#21--5details
#22ACCEPTED0.14 s1, 2, 3, 4, 5details
#23ACCEPTED0.14 s1, 2, 3, 4, 5details
#24--5details
#25--5details
#26--5details
#27--5details

Compiler report

Note: input/jumps2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Code

import java.util.*;

public class jumps2 {
    static TreeSet<Integer>[] r_safespaces;
    static TreeSet<Integer>[] c_safespaces;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine();

        String[] grid = new String[n];
        for (int i = 0; i < n; i++) grid[i] = sc.nextLine().trim();

        int[][] queries = new int[q][4];
        for (int i = 0; i < q; i++) {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();
            queries[i][2] = sc.nextInt();
            queries[i][3] = sc.nextInt();
        }

        r_safespaces = new TreeSet[n + 1];
        c_safespaces = new TreeSet[m + 1];
        for (int i = 0; i <= n; i++) r_safespaces[i] = new TreeSet<>();
        for (int i = 0; i <= m; i++) c_safespaces[i] = new TreeSet<>();

        for (int r = 1; r <= n; r++) {
            String row = grid[r - 1];
            for (int c = 1; c <= m; c++) {
                if (row.charAt(c - 1) == '.') {
                    r_safespaces[r].add(c);
                    c_safespaces[c].add(r);
                }
            }
        }

        for (int[] query : queries) {
            System.out.println(jump(query[0], query[1], query[2], query[3]));
        }
    }

    static int jump(int y1, int x1, int y2, int x2) {
        if (y1 == y2 && x1 == x2) return 0;

        Deque<int[]> queue = new ArrayDeque<>();
        queue.addLast(new int[]{0, y1, x1, 0});
        queue.addLast(new int[]{1, x1, y1, 0});

        while (!queue.isEmpty()) {
            int[] e = queue.removeFirst();
            int type = e[0], id = e[1], pos = e[2], dist = e[3];

            if (type == 0) {
                if (id == y2 && r_safespaces[id].contains(x2)) return dist + 1;
                TreeSet<Integer> rowSet = r_safespaces[id];
                Iterator<Integer> it = rowSet.iterator();
                while (it.hasNext()) {
                    int c = it.next();
                    queue.addLast(new int[]{1, c, id, dist + 1});
                    it.remove();
                }
            } else {
                if (id == x2 && c_safespaces[id].contains(y2)) return dist + 1;
                TreeSet<Integer> colSet = c_safespaces[id];
                Iterator<Integer> it = colSet.iterator();
                while (it.hasNext()) {
                    int r = it.next();
                    queue.addLast(new int[]{0, r, id, dist + 1});
                    it.remove();
                }
            }
        }
        return -1;
    }
}

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

Feedback: Incorrect character on line 4 col 1: expected "3", 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
2
1
3
-1
...

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

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
1
2
2
1
2
...

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

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
3
4
-1
-1
-1
...

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

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:

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

correct output
2
3
3
2
2
...

user output
2
3
4
-1
-1
...

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

Test 7

Group: 2, 5

Verdict:

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

correct output
2
2
2
2
3
...

user output
2
2
3
-1
-1
...

Feedback: Incorrect character on line 3 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
2
3
-1
-1
-1
...

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

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
(empty)

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
(empty)

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

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
(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:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
(empty)

Test 25

Group: 5

Verdict:

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

correct output
1
1
1
1
1
...

user output
(empty)

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