Submission details
Task:Hypyt
Sender:Emil
Submission time:2025-11-06 22:21: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.23 s2, 5details
#70.18 s2, 5details
#80.14 s2, 5details
#90.29 s3, 4, 5details
#100.30 s3, 4, 5details
#110.29 s3, 4, 5details
#120.30 s4, 5details
#130.30 s4, 5details
#140.30 s4, 5details
#150.50 s5details
#160.46 s5details
#170.40 s5details
#180.38 s5details
#190.36 s5details
#200.37 s5details
#210.30 s5details
#220.05 s1, 2, 3, 4, 5details
#230.05 s1, 2, 3, 4, 5details
#240.29 s5details
#250.27 s5details
#260.54 s5details
#27ACCEPTED0.28 s5details

Code

# Ratkaisu tehtävään "turvalliset ruudut ja hypyt"
# Mallinnus rivit + sarakkeet -graafina
# Lopussa korjattu hyppyjen laskenta: d//2 (+1 jos d>0)

import sys
from collections import deque

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):
        grid.append(list(next(it).strip()))

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

    # Lisää reunat rivin r ja sarakkeen n+c välille jos ruutu on turvallinen
    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 BFS jokaisesta solmusta
    all_dist = [None] * N
    for s in range(N):
        all_dist[s] = bfs(s, adj, N)

    INF = 10**9
    out_lines = []
    for _ in range(q):
        y1 = int(next(it)); x1 = int(next(it))
        y2 = int(next(it)); x2 = int(next(it))
        r1 = y1 - 1
        c1 = x1 - 1
        r2 = y2 - 1
        c2 = x2 - 1

        start_nodes = (r1, n + c1)
        end_nodes = (r2, n + c2)

        ans = INF
        for s in start_nodes:
            for t in end_nodes:
                d = all_dist[s][t]
                if d < ans:
                    ans = d

        if ans >= INF:
            out_lines.append("-1")
        else:
            jumps = ans // 2
            if ans > 0:
                jumps += 1
            out_lines.append(str(jumps))

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

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

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

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

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
7

user output
4

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

Test 6

Group: 2, 5

Verdict:

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

correct output
2
3
3
2
2
...

user output
1
2
2
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
2
...

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

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

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

Test 12

Group: 4, 5

Verdict:

input
80 80 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 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
2
1
1
2
1
...

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

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
1
2
0
1
1
...

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

Test 15

Group: 5

Verdict:

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

correct output
3
2
2
2
2
...

user output
2
1
1
1
1
...

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

Test 16

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 17

Group: 5

Verdict:

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

correct output
3
3
2
2
2
...

user output
2
2
1
1
1
...

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

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
2
2
2
2
2
...

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

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
52
211
73
47
33
...

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

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
29
78
19
33
49
...

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

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
249
249
249
249
249
...

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

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

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

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

Test 25

Group: 5

Verdict:

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

correct output
1
1
1
1
1
...

user output
0
0
0
0
0
...

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

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