Submission details
Task:Hypyt
Sender:Toitsu
Submission time:2025-10-30 15:38:27 +0200
Language:Python3 (PyPy3)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.05 s1, 2, 3, 4, 5details
#20.05 s1, 2, 3, 4, 5details
#30.05 s1, 2, 3, 4, 5details
#40.05 s1, 2, 3, 4, 5details
#50.05 s1, 2, 3, 4, 5details
#60.15 s2, 5details
#70.14 s2, 5details
#80.13 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
#220.05 s1, 2, 3, 4, 5details
#230.05 s1, 2, 3, 4, 5details
#24--5details
#25--5details
#26--5details
#27ACCEPTED0.40 s5details

Code

from collections import deque

height, width, question_count = input().split(" ")
height = int(height)
width = int(width)
question_count = int(question_count)

# create the grid from input
grid = []
for _ in range(height):
    grid.append(list(input()))

# read the questions from input
questions = []
for _ in range(question_count):
    data = input().split(" ")
    # convert 1-based Y1 X1 Y2 X2 to 0-based [(X2, Y2), (X2, Y2)]
    questions.append([(int(data[1]) - 1, int(data[0]) - 1), (int(data[3]) - 1, int(data[2]) - 1)])



# Build adjacency list for bipartite graph
adj = [[] for _ in range(height + width)]

for y in range(height):
    for x in range(width):
        if grid[y][x] == '.':
            row_node = y
            col_node = height + x
            adj[row_node].append(col_node)
            adj[col_node].append(row_node)



def bfs(start_x, start_y, end_x, end_y):
    # same cell
    if start_x == end_x and start_y == end_y:
        return 0

    # same row or column directly visible
    if start_y == end_y:
        for x in range(min(start_x, end_x), max(start_x, end_x) + 1):
            if grid[start_y][x] == '*':
                break
        else:
            return 1
    if start_x == end_x:
        for y in range(min(start_y, end_y), max(start_y, end_y) + 1):
            if grid[y][start_x] == '*':
                break
        else:
            return 1

    # --- BFS in bipartite graph ---
    start_nodes = [start_y, height + start_x]
    target_nodes = {end_y, height + end_x}

    dist = [-1] * (height + width)
    q = deque()

    for s in start_nodes:
        dist[s] = 0
        q.append(s)

    while q:
        u = q.popleft()
        for v in adj[u]:
            if dist[v] == -1:
                dist[v] = dist[u] + 1
                q.append(v)

    candidates = [dist[t] for t in target_nodes if dist[t] != -1]
    if not candidates:
        return -1
    return (min(candidates) + 1) // 2



# process questions
for question in questions:
    start_x, start_y = question[0]
    end_x, end_y = question[1]
    result = bfs(start_x, start_y, end_x, end_y)

    print(result)

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

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

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

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

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

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
1
2
1
1
2
...

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

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

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

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
1
1
1
1
1
...

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

input
10 1 10
*
*
.
*
...

correct output
0
1
1
0
0
...

user output
0
0
0
0
0
...

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

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

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

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

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

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...