Submission details
Task:Hypyt
Sender:sevti
Submission time:2025-10-27 15:23:43 +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.21 s2, 5details
#70.18 s2, 5details
#80.13 s2, 5details
#90.27 s3, 4, 5details
#100.27 s3, 4, 5details
#110.26 s3, 4, 5details
#120.27 s4, 5details
#130.27 s4, 5details
#140.28 s4, 5details
#150.46 s5details
#160.42 s5details
#170.38 s5details
#180.36 s5details
#190.33 s5details
#200.34 s5details
#21ACCEPTED0.25 s5details
#220.05 s1, 2, 3, 4, 5details
#230.05 s1, 2, 3, 4, 5details
#240.25 s5details
#250.26 s5details
#260.49 s5details
#27ACCEPTED0.20 s5details

Code

import sys
from collections import deque



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


def main():
    data = sys.stdin.read().splitlines()
    it = iter(data)
    n, m, q = map(int, next(it).split())
    grid = [list(next(it).strip()) for _ in range(n)]
    N = n + m
    adj = [[] for _ in range(N)]

    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)

    cache = {}
    out = []
    
    for _ in range(q):
        y1, x1, y2, x2 = map(int, next(it).split())
        y1 -= 1; x1 -= 1; y2 -= 1; x2 -= 1

        if y1 == y2 and x1 == x2:
            out.append("0")
            continue

        R1 = y1
        C1 = n + x1
        R2 = y2
        C2 = n + x2
        
        for node in [R1, C1, R2, C2]:
            if node not in cache:
                cache[node] = searcher(node, adj, N)
        
      
        ans = None      
        d1 = cache[R1][C2]
        d2 = cache[R2][C2]
        
        if d1 != -1 and d2 != -1:
            path = d1 + d2
            ans = path if ans is None else min(ans, path)
        
        d1 = cache[C1][R2]
        d2 = cache[C2][R2]
        
        if d1 != -1 and d2 != -1:
            path = d1 + d2
            ans = path if ans is None else min(ans, path)
        out.append(str(ans if ans is not None else -1))

    print("\n".join(out))



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

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

Test 2

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
1
2
2
...

user output
2
2
2
2
2
...

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

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
2
2
2
2
2
...

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

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
4
4
2
4
4
...

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

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
7

user output
8

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

Test 6

Group: 2, 5

Verdict:

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

correct output
2
3
3
2
2
...

user output
2
4
4
2
2
...

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

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

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
2
4
4
4
4
...

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

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

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

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
2
2
4
2
2
...

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

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
4
4
4
4
4
...

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

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

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

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
4
2
2
4
2
...

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

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
2
4
2
2
2
...

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

Test 15

Group: 5

Verdict:

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

correct output
3
2
2
2
2
...

user output
4
2
2
2
2
...

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

Test 16

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

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

Test 17

Group: 5

Verdict:

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

correct output
3
3
2
2
2
...

user output
4
4
2
2
2
...

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

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
4
4
4
4
4
...

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

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
104
422
146
94
66
...

Feedback: Incorrect character on line 3 col 3: expected "145", got "146"

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
58
156
38
66
98
...

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

Test 21

Group: 5

Verdict: ACCEPTED

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

correct output
498
498
498
498
498
...

user output
498
498
498
498
498
...

Test 22

Group: 1, 2, 3, 4, 5

Verdict:

input
10 1 10
*
*
.
*
...

correct output
0
1
1
0
0
...

user output
0
2
2
0
0
...

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

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

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

Test 24

Group: 5

Verdict:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
2
2
2
2
2
...

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

Test 25

Group: 5

Verdict:

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

correct output
1
1
1
1
1
...

user output
2
2
2
2
2
...

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

Test 26

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

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

Test 27

Group: 5

Verdict: ACCEPTED

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

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...