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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:58:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |       for (int j = 0; j < toCheck.size(); j++) {
      |                       ~~^~~~~~~~~~~~~~~~
input/code.cpp:64:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for (int k = 0; k < rowReach[toCheck[j]].size(); k++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:106:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for (int j = 0; j < rowReach[y1].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
input/code.cpp:118:23: warning: comparison of integer expressions of different signe...

Code

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

// DEBUGGGGG!!
// Smth is wrong for some reason.
// Unless cses is <sulfur translated to finnish and back to english>...

bool safe[250][250];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // freopen("output.txt", "r", stdin);
  int n, m, q;
  cin >> n >> m >> q;


  unordered_set<int>* rowAccess = new unordered_set<int>[n];
  vector<int>* rowReach = new vector<int>[n];

  for (int i = 0; i < n; i++) {
    string row;
    cin >> row;
    unordered_set<int> foundRows;
    for (int j = 0; j < m; j++) {
      bool isSafe = row[j] == '.';
      safe[i][j] = isSafe;
      // cout << "Safe? " << isSafe << endl;
      if (!isSafe) continue;
      rowAccess[i].insert(j);
      for (int k = 0; k < i; k++) {
        if (rowAccess[k].find(j) != rowAccess[k].end() && foundRows.find(k) == foundRows.end()) {
          rowReach[i].push_back(k);
          rowReach[k].push_back(i);
          foundRows.insert(k);
        }
      }
    }
  }

  int distance[250][250];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      distance[i][j] = -1;
    }
  }

  // Qualqulate the reach distance thng to the other rows - Should be O(n^2) max
  for (int i = 0; i < n; i++) {
    distance[i][i] = 0;
    bool checked[250] = {};
    // checked[i] = true;
    vector<int> toCheck = {i};
    int steps = 0;
    while (toCheck.size() > 0) {
      vector<int> newCheck;
      for (int j = 0; j < toCheck.size(); j++) {
        if (checked[toCheck[j]]) continue;
        checked[toCheck[j]] = true;
        // cout << i << " " << toCheck[j] << " " << steps << endl;
        // cout << "a" << endl;
        distance[i][toCheck[j]] = steps;
        for (int k = 0; k < rowReach[toCheck[j]].size(); k++) {
          if (checked[rowReach[toCheck[j]][k]]) continue;
          newCheck.push_back(rowReach[toCheck[j]][k]);
        }
      }
      toCheck = newCheck;
      ++steps;
    }
  }

  int* results = new int[q];
  for (int i = 0; i < q; i++) {
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    --y1; --x1; --y2; --x2;

    if (distance[y1][y2] == -1) {
      results[i] = -1;
      continue;
    }

    if (y1 == y2) {
      if (x1 == x2) {
        results[i] = 0;
        continue;
      } else {
        results[i] = 1;
        continue;
      }
    }

    if (distance[y1][y2] == 1 && x1 == x2) {
      results[i] = 1;
      continue;
    }

    // cout << "Row reach from " << y1 << " to " << y2 << " is " << distance[y1][y2] << endl;

    int result = 2 * distance[y1][y2] - 1;
    vector<int> fastStart;

    bool secondColumnMatch = false;
    for (int j = 0; j < rowReach[y1].size(); j++) {
      if (distance[rowReach[y1][j]][y2] == distance[y1][y2] - 1 && safe[rowReach[y1][j]][x1]) {
        secondColumnMatch = true;
        fastStart.push_back(rowReach[y1][j]);
      }
      // cout << "can reach " << rowReach[y1][j] << endl;
    }
    result += !secondColumnMatch;

    // cout << "fstart " << fastStart.size() << endl;

    bool secLastColumnMatch = false;
    for (int j = 0; j < rowReach[y2].size(); j++) {
      if (distance[y1][rowReach[y2][j]] == distance[y1][y2] - 1 && safe[rowReach[y2][j]][x2]) {
        if (!secondColumnMatch) {
          secLastColumnMatch = true;
          break;
        }
        for (int k = 0; k < fastStart.size(); k++) {
          if (distance[fastStart[k]][rowReach[y2][j]] == distance[y1][y2] - 2) {
            secLastColumnMatch = true;
            break;
          }
        }
        if (secLastColumnMatch) {
          break;
        }
      }
    }
    result += !secLastColumnMatch;

    if (result == 1 && x1 != x2) {
      ++result;
    }

    results[i] = result;
  }

  for (int i = 0; i < q; i++) {
    cout << results[i] << '\n';
  }

  // cout << "finished" << endl;
  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: 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: ACCEPTED

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

correct output
2
3
3
2
2
...

user output
2
3
3
2
2
...

Test 7

Group: 2, 5

Verdict: ACCEPTED

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

correct output
2
2
2
2
3
...

user output
2
2
2
2
3
...

Test 8

Group: 2, 5

Verdict: ACCEPTED

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

correct output
2
3
3
3
3
...

user output
2
3
3
3
3
...

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

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 13

Group: 4, 5

Verdict: ACCEPTED

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

correct output
3
2
2
3
2
...

user output
3
2
2
3
2
...

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

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

correct output
3
2
2
2
2
...

user output
3
2
2
2
2
...

Test 16

Group: 5

Verdict: ACCEPTED

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 17

Group: 5

Verdict: ACCEPTED

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

correct output
3
3
2
2
2
...

user output
3
3
2
2
2
...

Test 18

Group: 5

Verdict: ACCEPTED

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

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

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

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

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 27

Group: 5

Verdict: ACCEPTED

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

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...