Submission details
Task:Hypyt
Sender:worst
Submission time:2025-10-29 17:24:27 +0200
Language:C++ (C++20)
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
#6--2, 5details
#7--2, 5details
#8--2, 5details
#90.52 s3, 4, 5details
#100.52 s3, 4, 5details
#110.51 s3, 4, 5details
#120.64 s4, 5details
#130.61 s4, 5details
#140.59 s4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#190.88 s5details
#200.91 s5details
#210.70 s5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.52 s5details
#25ACCEPTED0.56 s5details
#26--5details
#27ACCEPTED0.55 s5details

Code

#include <bits/stdc++.h>

using namespace std;

map<pair<char, int>, vector<pair<char, int>>> G;
map<pair<char, int>, map<pair<char, int>, int>> dist;

void bfs(char rc, int i) {
    dist[{rc, i}][{rc, i}] = 0;
    queue<pair<char, int>> q;
    q.push({rc, i});

    while (!q.empty()) {
        pair<char, int> p = q.front();
        q.pop();

        for (pair<char, int> u : G[p]) {
            if (dist[{rc, i}][u] == -1) {
                q.push(u);
                dist[{rc, i}][u] = dist[{rc, i}][p] + 1;
            }
        }
    }
}

void solve() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<char>> v(n, vector<char>(m));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> v[i][j];
            if (v[i][j] == '.') {
                G[{'r', i}].push_back({'c', j});
                G[{'c', j}].push_back({'r', i});
            }
        }
    }

    for (int r = 0; r < n; r++) {
        for (int i = 0; i < n; i++) {
            dist[{'r', r}][{'r', i}] = -1;
        }
        for (int j = 0; j < m; j++) {
            dist[{'r', r}][{'c', j}] = -1;
        }
        bfs('r', r);
    }

    for (int c = 0; c < m; c++) {
        for (int i = 0; i < n; i++) {
            dist[{'c', c}][{'r', i}] = -1;
        }
        for (int j = 0; j < m; j++) {
            dist[{'c', c}][{'c', j}] = -1;
        }
        bfs('c', c);
    }

    while (q--) {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        y1--;
        x1--;
        y2--;
        x2--;
        if (y1 == y2 && x1 == x2) {
            cout << 0 << endl;
            continue;
        }
        int ans = dist[{'r', y1}][{'c', x2}];
        ans = min(ans, dist[{'c', x1}][{'r', y2}]);
        cout << ans << endl;
    }
}

int main() {
    solve();
    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
(empty)

Test 7

Group: 2, 5

Verdict:

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

correct output
2
2
2
2
3
...

user output
(empty)

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
(empty)

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