Submission details
Task:Hypyt
Sender:Lytsky
Submission time:2025-11-07 22:15:03 +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.07 s2, 5details
#70.06 s2, 5details
#80.05 s2, 5details
#90.17 s3, 4, 5details
#100.18 s3, 4, 5details
#110.18 s3, 4, 5details
#120.18 s4, 5details
#130.18 s4, 5details
#140.18 s4, 5details
#150.26 s5details
#160.25 s5details
#170.24 s5details
#180.24 s5details
#190.24 s5details
#200.23 s5details
#21ACCEPTED0.21 s5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.19 s5details
#25ACCEPTED0.18 s5details
#260.27 s5details
#27ACCEPTED0.22 s5details

Code

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m, q, ekay, ekax, tokay, tokax;
    cin >> n >> m >> q;
    string row;
    vector<int> nodesInColumns[m];
    vector<int> nodesInRows[n];
    vector<int> col_dists[m], row_dists[n];
    string answers;
    string grid[n];
    for (int index = 0; index < m; index++) {
        vector<int> s(m, 1e9);
        col_dists[index] = s;
    }

    for (int index = 0; index < n; index++) {
        cin >> row;
        grid[index] = row;
        for (int col = 0; col < m; col++) {
            if (grid[index][col] == '.') {
                nodesInColumns[col].push_back(index);
                nodesInRows[index].push_back(col);
            }
        }
        vector<int> s(n, 1e9);
        row_dists[index] = s;
    }
    for (int index = 0; index < m; index++) {
        for (int j = 0; j < (int) nodesInColumns[index].size(); j++) {
            for (int i = j; i < (int) nodesInColumns[index].size(); i++) {
                if (nodesInColumns[index][j] < nodesInColumns[index][i]) {
                    if (row_dists[nodesInColumns[index][j]][nodesInColumns[index][i]] != 1) {
                        pair<vector<int>,vector<int>> p = {{nodesInColumns[index][i]}, {nodesInColumns[index][j]}};
                        row_dists[nodesInColumns[index][j]][nodesInColumns[index][i]] = 1;
                    }
                } else if (nodesInColumns[index][j] == nodesInColumns[index][i]) {
                    row_dists[nodesInColumns[index][j]][nodesInColumns[index][i]] = 0;
                }
            }
        }
    }
    for (int index = 0; index < n; index++) {
        for (int j = 0; j < (int) nodesInRows[index].size(); j++) {
            for (int i = j; i < (int) nodesInRows[index].size(); i++) {
                if (nodesInRows[index][j] < nodesInRows[index][i]) {
                    if (col_dists[nodesInRows[index][j]][nodesInRows[index][i]] != 1) {
                        pair<vector<int>,vector<int>> p = {{nodesInRows[index][i]}, {nodesInRows[index][j]}};
                        col_dists[nodesInRows[index][j]][nodesInRows[index][i]] = 1;
                    }
                } else if (nodesInRows[index][j] == nodesInRows[index][i]) {
                    col_dists[nodesInRows[index][j]][nodesInRows[index][i]] = 0;
                }
            }
        }
    }
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                row_dists[i][j] = min(row_dists[i][j], row_dists[min(i,k)][max(i,k)] + row_dists[min(k,j)][max(k,j)]);
            }
        }
    }
    for (int k = 0; k < m; k++) {
        for (int i = 0; i < m; i++) {
            for (int j = i+1; j < m; j++) {
                col_dists[i][j] = min(col_dists[i][j], col_dists[min(i,k)][max(i,k)] + col_dists[min(k,j)][max(k,j)]);
            }
        }
    }
    for (int index = 0; index < q; index++) {
        cin >> ekay >> ekax >> tokay >> tokax;
        int y1, y2, x1, x2;
        if (ekay < tokay) {
            y1 = ekay;
            y2 = tokay;
            x1 = ekax;
            x2 = tokax;
        } else {
            y1 = tokay;
            y2 = ekay;
            x1 = tokax;
            x2 = ekax;
        }
        if (y1 == y2 && x1 == x2) answers += "0\n";
        else if (y1 == y2 || x1 == x2) answers += "1\n";
        else {
            if (row_dists[y1-1][y2-1] >= 1e9) answers += "-1\n";
            else {
                answers += to_string(row_dists[y1-1][y2-1] + col_dists[x1-1][x2-1]) + "\n";
            }
        }
    }
    printf("%s", answers.c_str());
}

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

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

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
1
2
1000000001
1
1000000001
...

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

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
1000000001
4
1000000001
3
4
...

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

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

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

Test 7

Group: 2, 5

Verdict:

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

correct output
2
2
2
2
3
...

user output
2
2
1000000001
1000000001
2
...

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

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
1000000001
2
1000000001
2
2
...

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

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
1000000001
1000000001
2
...

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

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
2
1
2
1000000001
2
...

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

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
2
1000000001
1000000001
3
1000000002
...

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

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

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
1000000001
1000000001
1000000001
2
2
...

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

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
2
2
1
1000000001
2
...

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

Test 15

Group: 5

Verdict:

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

correct output
3
2
2
2
2
...

user output
2
1000000001
2
2
1000000001
...

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

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

Test 17

Group: 5

Verdict:

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

correct output
3
3
2
2
2
...

user output
1000000001
1000000001
2
1000000001
2
...

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

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
2
2
1000000001
1000000001
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
1000000052
1000000211
1000000073
93
1000000033
...

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

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
57
1000000078
1000000019
1000000033
98
...

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

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

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

Test 27

Group: 5

Verdict: ACCEPTED

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

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...