Submission details
Task:Hypyt
Sender:xheater
Submission time:2025-11-07 22:47:55 +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
#80.93 s2, 5details
#90.18 s3, 4, 5details
#100.18 s3, 4, 5details
#110.18 s3, 4, 5details
#120.26 s4, 5details
#130.22 s4, 5details
#140.19 s4, 5details
#15--5details
#16--5details
#17--5details
#180.41 s5details
#190.21 s5details
#200.22 s5details
#210.20 s5details
#220.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#240.00 s5details
#25ACCEPTED0.19 s5details
#26--5details
#27ACCEPTED0.21 s5details

Code

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <unordered_map>

using namespace std;

struct item{
    pair<int, int> pos;
    int dist;
    int start_X;
};
struct pack{
    int dist;
    int startX;
    int endX;
};

vector<pack> evil_BFS(int start_row, const vector<int> rows[], bool visited[],
    int m, const vector<int> columns[], int n){
    //memset(visited, false, n*m);
    queue<item> nodes;
    vector<int> start = rows[start_row];
    vector<pack> distances(n, {-1, -1, -1});
    for(int& pos : start){
        nodes.push({{pos, start_row}, 0, pos});
        visited[start_row * m + pos] = true;
        //cout << "start "<< pos << " "<<start_row << char(10);
    }
    while (!nodes.empty()){
        item next = nodes.front();
        nodes.pop();
        int X = next.pos.first;
        int Y = next.pos.second;

        //cout << "next " << X << " " << Y << " " << next.dist <<char(10);

        if(distances[Y].dist == -1){
            distances[Y].dist = next.dist;
            distances[Y].startX = next.start_X;
            distances[Y].endX = X; 
        }

        for(int a : rows[Y]){
            //cout << "row "<<a << Y<<char(10);
            if(!visited[Y * m + a]){
                visited[Y * m + a] = true;
                nodes.push({{a, Y}, next.dist + 1, next.start_X});
            }
        }
        for(int a : columns[X]){
            if(!visited[a * m + X]){
                visited[a * m + X] = true;
                nodes.push({{X, a}, next.dist + 1, next.start_X});
            }
        }
    }
    /*for(int i = 0; i < n; i++){
        if(distances[i] == 0 && i != start_row){
            //distances[i] = -1;
        }
    }*/
    return distances;
}

int main(){
    // n height, m width
    int n, m, q;
    cin >> n >> m >> q;
    char grid[m][n];
    bool visited[n*m] = {0};
    int ans[q] = {};

    vector<int> rows[n] = {};
    vector<int> columns[m] = {};

    vector<vector<pack>> dist(n);

    for (int i = 0; i < n ; i++){
        string line;
        cin >> line;
        for(int j = 0; j < m ; j++){
            grid[i][j] = line[j];
            if(grid[i][j] == '.'){
                rows[i].emplace_back(j);
                columns[j].emplace_back(i);
            }
        }
    }
    for(int i = 0; i < n; i++){
        memset(visited, 0, m*n);
        dist[i] = evil_BFS(i, rows, visited, m, columns, n);
    }
    for(int i = 0; i < q; i++){
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;

        if(!(y1==y2 && x1 == x2)){
            pack current = dist[y1-1][y2-1];
            if(current.dist == -1){
                ans[i] = -1;
            }else{
                if(current.startX == x1 && current.endX == x2 && current.dist != 0){
                    ans[i] = current.dist;
                }else if(current.startX == current.endX && current.dist == 0){
                    ans[i] = 1;
                }else if(current.startX == x1 && current.endX != x2){
                    ans[i] = current.dist + 1;
                }else if(current.startX != x1 && current.endX == x2){
                    ans[i] = current.dist + 1;
                }else{
                    ans[i] = current.dist + 2;
                }
            }
        }else{
            ans[i] = 0;
        }
    }
    for(int i = 0; i < q; i++){
        cout << ans[i] << char(10);
    }
    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
3
3
1
3
3
...

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

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
1
3
3
1
3
...

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

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
3
5
3
3
5
...

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

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

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

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
3
3
3
3
3
...

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

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
3
1
3
3
3
...

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

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
3
3
2
3
5
...

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

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

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
3
3
3
3
3
...

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

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
3
3
3
3
3
...

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

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

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

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
105
423
147
93
67
...

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

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
57
157
39
67
99
...

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

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
499
499
499
499
499
...

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

Test 22

Group: 1, 2, 3, 4, 5

Verdict:

input
10 1 10
*
*
.
*
...

correct output
0
1
1
0
0
...

user output
(empty)

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:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
(empty)

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