Submission details
Task:Hypyt
Sender:Emil
Submission time:2025-11-06 22:18:58 +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.25 s2, 5details
#70.20 s2, 5details
#80.14 s2, 5details
#90.36 s3, 4, 5details
#100.35 s3, 4, 5details
#110.34 s3, 4, 5details
#120.36 s4, 5details
#130.36 s4, 5details
#140.35 s4, 5details
#150.58 s5details
#160.54 s5details
#170.46 s5details
#180.42 s5details
#190.44 s5details
#200.43 s5details
#210.39 s5details
#220.05 s1, 2, 3, 4, 5details
#230.05 s1, 2, 3, 4, 5details
#240.32 s5details
#250.31 s5details
#260.64 s5details
#270.32 s5details

Code

import sys
from collections import deque

def read_ints():
    return list(map(int, sys.stdin.readline().split()))

def bfs(start, adj, N):
    INF = 10**9
    dist = [INF]*N
    dq = deque([start])
    dist[start] = 0
    while dq:
        u = dq.popleft()
        for v in adj[u]:
            if dist[v] == INF:
                dist[v] = dist[u] + 1
                dq.append(v)
    return dist

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    n = int(next(it)); m = int(next(it)); q = int(next(it))
    grid = []
    for _ in range(n):
        row = list(next(it).strip())
        grid.append(row)

    N = n + m  # numeroidaan rivit 0..n-1, sarakkeet n..n+m-1
    adj = [[] for _ in range(N)]

    # Lisää reunat rivin r (0..n-1) <-> sarake (n+c-1)
    for r in range(n):
        for c in range(m):
            if grid[r][c] == '.':
                u = r
                v = n + c
                adj[u].append(v)
                adj[v].append(u)

    # Esilasketaan etäisyydet jokaisesta solmusta kaikkiin solmuihin
    INF = 10**9
    all_dist = [None]*N
    for s in range(N):
        all_dist[s] = bfs(s, adj, N)

    out_lines = []
    for _ in range(q):
        y1 = int(next(it)); x1 = int(next(it)); y2 = int(next(it)); x2 = int(next(it))
        # indeksoidaan nollapohjaisesti
        r1 = y1 - 1
        c1 = x1 - 1
        r2 = y2 - 1
        c2 = x2 - 1
        s_nodes = (r1, n + c1)
        t_nodes = (r2, n + c2)
        ans = INF
        for s in s_nodes:
            for t in t_nodes:
                d = all_dist[s][t]
                if d < ans:
                    ans = d
        if ans >= INF:
            out_lines.append("-1")
        else:
            out_lines.append(str(ans/2))

    sys.stdout.write("\n".join(out_lines))

if __name__ == "__main__":
    main()

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

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

Test 2

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
1
2
2
...

user output
0.0
0.5
0.0
0.5
0.5
...

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

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
0.0
0.5
0.5
0.0
0.5
...

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

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
1.0
1.5
0.5
1.0
1.5
...

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

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
7

user output
3.0

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

Test 6

Group: 2, 5

Verdict:

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

correct output
2
3
3
2
2
...

user output
0.5
1.0
1.0
0.5
0.5
...

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

Test 7

Group: 2, 5

Verdict:

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

correct output
2
2
2
2
3
...

user output
0.5
0.5
0.5
0.5
1.0
...

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

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
0.5
1.0
1.0
1.0
1.0
...

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

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
0.5
0.5
0.5
0.5
0.5
...

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

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
0.5
0.0
1.0
0.5
0.5
...

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

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
1.0
1.0
1.0
1.0
1.0
...

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

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
0.5
0.5
0.5
0.5
0.5
...

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

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
1.0
0.5
0.5
1.0
0.5
...

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

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
0.5
1.0
0.0
0.5
0.5
...

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

Test 15

Group: 5

Verdict:

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

correct output
3
2
2
2
2
...

user output
1.0
0.5
0.5
0.5
0.5
...

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

Test 16

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
0.5
0.5
0.5
0.5
0.5
...

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

Test 17

Group: 5

Verdict:

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

correct output
3
3
2
2
2
...

user output
1.0
1.0
0.5
0.5
0.5
...

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

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
1.0
1.0
1.0
1.0
1.0
...

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

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
51.5
210.5
72.0
46.0
32.0
...

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

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
28.0
77.0
18.5
32.0
48.5
...

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

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
248.5
248.5
248.5
248.5
248.5
...

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

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

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

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

Test 24

Group: 5

Verdict:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
0.0
0.0
0.0
0.0
0.0
...

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

Test 25

Group: 5

Verdict:

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

correct output
1
1
1
1
1
...

user output
0.0
0.0
0.0
0.0
0.0
...

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

Test 26

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
0.5
0.5
0.5
0.5
0.5
...

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

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

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