Submission details
Task:Hypyt
Sender:False_Void1
Submission time:2025-10-30 20:14:19 +0200
Language:C++ (C++11)
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4, 5details
#2ACCEPTED0.00 s1, 2, 3, 4, 5details
#3ACCEPTED0.00 s1, 2, 3, 4, 5details
#4ACCEPTED0.00 s1, 2, 3, 4, 5details
#5ACCEPTED0.00 s1, 2, 3, 4, 5details
#6--2, 5details
#7--2, 5details
#8--2, 5details
#9--3, 4, 5details
#10--3, 4, 5details
#11--3, 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
#24--5details
#25--5details
#26--5details
#27--5details

Compiler report

input/code.cpp: In function 'long long int bfs(long long int, long long int, long long int, long long int, std::vector<std::vector<char> >&, std::vector<std::unordered_set<int> >&, std::vector<std::unordered_set<int> >&)':
input/code.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         auto [cy, cx] = q.front();
      |              ^

Code

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;

#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x).size()

const int MOD = 1e9 + 7;
const ll INF = 1e18;

ll y;
ll x;

ll bfs(ll y1, ll x1, ll y2, ll x2, vector<vector<char> > &grid, vector<unordered_set<int> > &unvisited_x, vector<unordered_set<int> > &unvisited_y)
{
    queue<pair<int, int> > q;
    q.push(make_pair(y2, x2));

    unvisited_x[x2].erase(y2);
    unvisited_y[y2].erase(x2);

    vector<vector<int> > dist(y + 1, vector<int>(x + 1, -1));
    dist[y2][x2] = 0;

    while (!q.empty())
    {
        auto [cy, cx] = q.front();
        q.pop();

        if (cy == y1 && cx == x1)
        {
            return dist[cy][cx];
        }
        vector<int> to_remove_y;
        for (ll y_test : unvisited_x[cx])
        {
            if (grid[y_test][cx] == '.' && dist[y_test][cx] == -1)
            {
                dist[y_test][cx] = dist[cy][cx] + 1;
                q.push(make_pair(y_test, cx));
                to_remove_y.push_back(y_test);

                if (grid[y_test][cx] == '#') {
                    to_remove_y.push_back(y_test);
                }
            }
        }
        for (ll t : to_remove_y)
            unvisited_x[cx].erase(t);

        vector<int> to_remove_x;
        for (ll x_test : unvisited_y[cy])
        {
            if (grid[cy][x_test] == '.' && dist[cy][x_test] == -1)
            {
                dist[cy][x_test] = dist[cy][cx] + 1;
                q.push(make_pair(cy, x_test));
                to_remove_x.push_back(x_test);
            }
            if (grid[cy][x_test] == '#') {
                to_remove_x.push_back(x_test);
            }
        }
        for (ll t : to_remove_x)
            unvisited_y[cy].erase(t);
    }

    return -1; 
}

int main()
{
    fastio
        ll q;
    cin >> y >> x >> q;

    vector<vector<char> > grid(y + 1, vector<char>(x + 1));
    for (ll i = 0; i < y; i++)
    {
        for (ll j = 0; j < x; j++)
        {
            cin >> grid[i][j];
        }
    }

    for (ll i = 0; i < q; i++)
    {
        vector<unordered_set<int> > unvisited_x(x + 1);
        vector<unordered_set<int> > unvisited_y(y + 1);

        for (int i = 0; i <= x; i++)
            for (int j = 0; j <= y; j++)
                unvisited_x[i].insert(j);

        for (int j = 0; j <= y; j++)
            for (int i = 0; i <= x; i++)
                unvisited_y[j].insert(i);

        ll y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        y1--;
        x1--;
        y2--;
        x2--;

        if (y1 == y2 && x1 == x2)
        {
            cout << 0 << "\n";
        }
        else
        {
            ll res = bfs(y1, x1, y2, x2, grid, unvisited_x, unvisited_y);

            cout << res << " ";
        }
    }
}

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: ACCEPTED

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

correct output
1
2
1
2
2
...

user output
1 2 1 2 2 2 2 2 1 2 

Test 3

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

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

correct output
1
2
2
1
2
...

user output
1 2 2 1 2 2 1 3 2 2 

Test 4

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

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

correct output
3
4
2
3
4
...

user output
3 4 2 3 4 2 -1 3 1 2 

Test 5

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

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

correct output
7

user output

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

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
(empty)

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
(empty)

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
1 0
1 1 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 1 0
1 0

Test 24

Group: 5

Verdict:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
(empty)

Test 25

Group: 5

Verdict:

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

correct output
1
1
1
1
1
...

user output
(empty)

Test 26

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Test 27

Group: 5

Verdict:

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

correct output
0
0
0
0
0
...

user output
(empty)