Submission details
Task:Hypyt
Sender:OorigamiK
Submission time:2025-11-01 00:34:02 +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
#60.10 s2, 5details
#70.09 s2, 5details
#80.08 s2, 5details
#90.23 s3, 4, 5details
#100.24 s3, 4, 5details
#110.23 s3, 4, 5details
#120.32 s4, 5details
#130.40 s4, 5details
#140.32 s4, 5details
#150.91 s5details
#16--5details
#170.83 s5details
#180.61 s5details
#19ACCEPTED0.47 s5details
#200.46 s5details
#21ACCEPTED0.44 s5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.21 s5details
#25ACCEPTED0.19 s5details
#260.59 s5details
#27ACCEPTED0.23 s5details

Code

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <unordered_map>

using namespace std;

int minDist(vector<vector<bool>>& grid, vector<vector<bool>>& rowAccess, vector<vector<int>>& rowDists, int n, int x1, int y1, int x2, int y2){
    if (!grid[y2][x2] || rowDists[y1][y2]==-1){
        return -1;
    }
    if (x1==x2 && y1==y2){
        return 0;
    }
    if (x1==x2 || y1==y2){
        return 1;
    }

    int k = rowDists[y1][y2];
    int startParity=0;
    for (int y=0;y<n;y++){
        if (grid[y][x1]){
            if (rowDists[y][y2]==k-1){
                startParity=1;
            }
        }
    }

    int endParity=0;
    for (int y=0;y<n;y++){
        if (grid[y][x2]){
            if (rowDists[y][y1]==k-1){
                endParity=1;
            }
        }
    }
    return 2*k+1-startParity-endParity;
}

void calcRowDists(vector<vector<bool>>& rowAcces, vector<vector<int>>& rowDists, int n){
    for (int i=0;i<n;i++){
        stack<int> curRows;
        stack<int> nextRows;
        nextRows.push(i);
        vector<bool> doneRows(n,false);
        doneRows[i]=true;
        rowDists[i][i]=0;
        int k=1;
        while (!nextRows.empty()){
            curRows=nextRows;
            nextRows={};
            while (!curRows.empty()){
                int curRow=curRows.top();
                for (int row=0;row<n;row++){
                    if (rowAcces[curRow][row] && !doneRows[row]){
                        nextRows.push(row);
                        doneRows[row]=true;
                        rowDists[i][row]=k;
                    }
                }
                curRows.pop();
            }
            k++;
        }
    }
}

int main(){
    int n,m,q;
    cin>>n>>m>>q;

    vector<vector<bool>> grid(n, vector<bool>(m,0));
    vector<vector<bool>> rowAccess(n, vector<bool>(n, false));
    vector<vector<int>> rowDists(n, vector<int>(n, -1));

    for (int i=0;i<n;i++){
        string s;
        cin>>s;
        for (int j=0;j<m;j++){
            grid[i][j]=(s[j]=='.');
        }
    }

    for (int i=0;i<m;i++){
        vector<int> rows;
        for (int j=0;j<n;j++){
            if (grid[j][i]){
                rows.push_back(j);
            }
        }
        for (int row : rows){
            for (int row1 : rows){
                rowAccess[row][row1]=true;
            }
        }
    }

    calcRowDists(rowAccess, rowDists, n);    

    vector<int> input(4*q, 0);
    for (int i=0;i<q;i++){
        int x1,x2,y1,y2;
        cin>>y1>>x1>>y2>>x2;
        input[4*i+0]=x1;
        input[4*i+1]=y1;
        input[4*i+2]=x2;
        input[4*i+3]=y2;
    }
    
    for (int i=0;i<q;i++){
        int x1=input[4*i+0];
        int y1=input[4*i+1];
        int x2=input[4*i+2];
        int y2=input[4*i+3];
        cout<<minDist(grid, rowAccess, rowDists , n, x1-1, y1-1, x2-1, y2-1)<<"\n";
    }
}

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

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

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

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

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

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

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

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

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 75 col 1: expected "4", got "3"

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
2
2
1
1
1
...

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

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

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

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

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

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 35 col 1: expected "2", got "1"

Test 19

Group: 5

Verdict: ACCEPTED

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

correct output
104
422
145
93
65
...

user output
104
422
145
93
65
...

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
57
155
38
65
98
...

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

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