Submission details
Task:Hypyt
Sender:Karjalanp11rakka
Submission time:2025-11-01 14:07:47 +0200
Language:C++ (C++20)
Status:READY
Result:25
Feedback
groupverdictscore
#1ACCEPTED10
#20
#3ACCEPTED15
#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
#9ACCEPTED0.28 s3, 4, 5details
#10ACCEPTED0.17 s3, 4, 5details
#11ACCEPTED0.11 s3, 4, 5details
#12--4, 5details
#13--4, 5details
#14ACCEPTED0.41 s4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19ACCEPTED0.13 s5details
#20ACCEPTED0.17 s5details
#21ACCEPTED0.10 s5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.10 s5details
#25ACCEPTED0.10 s5details
#26--5details
#27ACCEPTED0.11 s5details

Code

#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> t;
vector<vector<vector<pair<size_t, size_t>>>> p;
size_t n, m, q;
// vector<vector<int>> g;
// vector<vector<int>> z;
// void dfs(size_t i, size_t j, int gi)
// {
//   if(z[i][j] || t[i][j] == '*') return;
//   z[i][j] = 1;
//   g[i][j] = gi;
//   for(auto l : p[i][j]) dfs(l.first, l.second, gi);
// }
int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> q;
  t = vector<vector<char>>(n, vector<char>(m));
  for(size_t i {}; i < n; ++i)
    for(size_t j {}; j < m; ++j)
      cin >> t[i][j];
  p = vector<vector<vector<pair<size_t, size_t>>>>(n, vector<vector<pair<size_t, size_t>>>(m));
  for(size_t i {}; i < n; ++i)
    for(size_t j {}; j < m; ++j)
    {
      if(t[i][j] == '*') continue;
      for(size_t k = j + 1; k < m; ++k)
      {
        if(t[i][k] == '*') continue;
        p[i][j].emplace_back(i, k);
        p[i][k].emplace_back(i, j);
      }
    }
  for(size_t j {}; j < m; ++j)
    for(size_t i {}; i < n; ++i)
    {
      if(t[i][j] == '*') continue;
      for(size_t k = i + 1; k < n; ++k)
      {
        if(t[k][j] == '*') continue;
        p[i][j].emplace_back(k, j);
        p[k][j].emplace_back(i, j);
      }
    }
  // z = vector<vector<int>>(n, vector<int>(m));
  // g = vector<vector<int>>(n, vector<int>(m));
  // int gi {};
  // for(size_t i {}; i < n; ++i)
  //   for(size_t j {}; j < m; ++j)
  //     dfs(i, j, gi++);
  unordered_map<size_t, unordered_map<size_t, vector<tuple<size_t, size_t, size_t>>>> qs;
  for(size_t i {}; i < q; ++i)
  {
    size_t y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    --y1;
    --x1;
    --y2;
    --x2;
    if(qs[y1][x1].size())
      qs[y1][x1].push_back(make_tuple(y2, x2, i));
    else
      qs[y2][x2].push_back(make_tuple(y1, x1, i));
  }
  vector<int> s(q, 0);
  for(auto y1 : qs)
    for(auto x1 : y1.second)
    {
      vector<vector<int>> d(n, vector<int>(m, -1));
      d[y1.first][x1.first] = 0;
      queue<tuple<size_t, size_t, int>> w;
      w.push(make_tuple(y1.first, x1.first, 0));
      while(!w.empty())
      {
        for(auto l : p[get<0>(w.front())][get<1>(w.front())])
          if(d[l.first][l.second] == -1)
          {
            d[l.first][l.second] = get<2>(w.front()) + 1;
            w.push(make_tuple(l.first, l.second, get<2>(w.front()) + 1));
          }
        w.pop();
      }
      for(auto t : x1.second) s[get<2>(t)] = d[get<0>(t)][get<1>(t)];
    }
  for(int a : s) cout << a << '\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: ACCEPTED

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

correct output
1
2
1
2
2
...

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

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

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

Test 9

Group: 3, 4, 5

Verdict: ACCEPTED

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 10

Group: 3, 4, 5

Verdict: ACCEPTED

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

correct output
2
1
3
2
2
...

user output
2
1
3
2
2
...

Test 11

Group: 3, 4, 5

Verdict: ACCEPTED

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

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

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

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

correct output
2
3
1
2
2
...

user output
2
3
1
2
2
...

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

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

correct output
104
422
145
93
65
...

user output
104
422
145
93
65
...

Test 20

Group: 5

Verdict: ACCEPTED

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

correct output
57
155
38
65
98
...

user output
57
155
38
65
98
...

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