Submission details
Task:Hypyt
Sender:False_Void1
Submission time:2025-11-07 17:26:57 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4, 5details
#20.00 s1, 2, 3, 4, 5details
#30.00 s1, 2, 3, 4, 5details
#40.00 s1, 2, 3, 4, 5details
#5ACCEPTED0.00 s1, 2, 3, 4, 5details
#60.15 s2, 5details
#70.15 s2, 5details
#80.15 s2, 5details
#90.08 s3, 4, 5details
#100.08 s3, 4, 5details
#110.08 s3, 4, 5details
#120.08 s4, 5details
#130.08 s4, 5details
#140.08 s4, 5details
#150.23 s5details
#160.23 s5details
#170.23 s5details
#180.23 s5details
#190.20 s5details
#200.21 s5details
#210.20 s5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.09 s5details
#25ACCEPTED0.09 s5details
#260.23 s5details
#27ACCEPTED0.19 s5details

Code

#include <bits/stdc++.h> 
using namespace std;

#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

#define ll long long
const ll INF = 1e15;

ll n, m;
vector<vector<char> > grid;
vector<vector<ll> > D;

void precomputeFloydWarshall() { // PLEEEEEEESE WWWOOOOORRRKKKK
    ll V = n + m; 
    D = vector<vector<ll> >(V, vector<ll>(V, INF));

    for (ll i = 0; i < V; i++)
    {
        D[i][i] = 0;
    }

    for (ll r = 0; r < n; r++)
    {
        for (ll c = 0; c < m; c++)
        {
            if (grid[r][c] == '.')
            {
                ll row_node = r;
                ll col_node = n + c;

                D[row_node][col_node] = 1;
                D[col_node][row_node] = 1;
            }
        }
    }

    for (ll k = 0; k < V; k++)
    {
        for (ll i = 0; i < V; i++)
        {
            for (ll j = 0; j < V; j++)
            {
                if (D[i][k] < INF && D[k][j] < INF)
                {
                    D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
                }
            }
        }
    }
}

ll getMinJumps(ll y1, ll x1, ll y2, ll x2)
{
    if (grid[y1][x1] == '*' || grid[y2][x2] == '*')
        return -1;

    if (y1 == y2 && x1 == x2)
        return 0;

    ll r1_node = y1;
    ll c1_node = n + x1;
    ll r2_node = y2;
    ll c2_node = n + x2;

    ll result = min(D[r1_node][c2_node], D[c1_node][r2_node]);
    if (result >= INF)
        return -1;
    return result;
}

int main() {
    fastio;
    ll q;
    cin >> n >> m >> q;

    grid = vector<vector<char> >(n, vector<char>(m));
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < m; j++)
        {
            cin >> grid[i][j];
        }
    }

    precomputeFloydWarshall();

    while (q--)
    {
        ll y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        y1--;
        x1--;
        y2--;
        x2--;

        cout << getMinJumps(y1, x1, y2, x2) << "\n";
    }
    return 0;
}

Test details

Test 1 (public)

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
4 6 5
.*.***
*...**
*****.
*..*.*
...

correct output
1
0
3
3
-1

user output
1
0
3
3
-1

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

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

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

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

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

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

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

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

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

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

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

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

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

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

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

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

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
103
421
145
93
65
...

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

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
57
155
37
65
97
...

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

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
497
497
497
497
497
...

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

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

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 25

Group: 5

Verdict: ACCEPTED

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

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

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