Submission details
Task:Hypyt
Sender:OorigamiK
Submission time:2025-10-31 20:43:26 +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.06 s2, 5details
#70.04 s2, 5details
#80.02 s2, 5details
#90.96 s3, 4, 5details
#100.76 s3, 4, 5details
#110.56 s3, 4, 5details
#12--4, 5details
#13--4, 5details
#14--4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19--5details
#20--5details
#21--5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.19 s5details
#25ACCEPTED0.18 s5details
#26--5details
#27ACCEPTED0.21 s5details

Code

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

using namespace std;

struct Row{
    int parity;
    int index;
};

int minDist(vector<vector<bool>>& grid, vector<vector<bool>>& rowAcces, int n, int x1, int y1, int x2, int y2){
    if (x1==x2 && y1==y2){
        return 0;
    }
    if (x1==x2 || y1==y2){
        return 1;
    }
    stack<Row> curRows={};
    stack<Row> nextRows;

    vector<bool> doneRows(n, true);


    for (int y=0;y<n;y++){
        if (grid[y][x1] && y!=y1){
            doneRows[y]=false;
            nextRows.push({1, y});
            //cout<<"row "<<y<<" parity"<<1<<"\n";
        }
    }

    nextRows.push({0,y1});
    doneRows[y1]=false;
    int k=1;
    while (!nextRows.empty()){
        //cout<<"k "<<k<<"\n";
        curRows=nextRows;
        nextRows={};
        while (!curRows.empty()){
            Row curRow = curRows.top();

            for (int row=0;row<n;row++){
                if (rowAcces[curRow.index][row]){
                    if (doneRows[row]){
                        doneRows[row]=false;
                        //cout<<"row "<<row<<" parity"<<curRow.parity<<"\n";
                        if (row==y2){
                            if (grid[curRow.index][x2]){
                                return 2*k+curRow.parity;
                            }
                            else{
                                return 2*k+curRow.parity+1;
                            }
                        }
                        nextRows.push({curRow.parity, row});
                    }
                }
            }
            curRows.pop();
        }
        k++;
    }
    return -1;
}

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

    vector<vector<bool>> grid(n, vector<bool>(m,0));

    vector<vector<bool>> rowAcces(n, vector<bool>(n, false));

    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){
                rowAcces[row][row1]=true;
            }
        }
    }

    //int x1,x2,y1,y2;
    //cin>>y1>>x1>>y2>>x2;
    //cout<<minDist(grid, rowAcces, n, x1-1, y1-1, x2-1, y2-1)<<"\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, rowAcces, 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
4
-1
3
4
...

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

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

Feedback: Incorrect character on line 5 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
(empty)

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
(empty)

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
(empty)

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
(empty)

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
(empty)

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
(empty)

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