Submission details
Task:Hypyt
Sender:Tmotomaster
Submission time:2025-11-04 21:32:25 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.01 s1, 2, 3, 4, 5details
#20.01 s1, 2, 3, 4, 5details
#30.01 s1, 2, 3, 4, 5details
#40.01 s1, 2, 3, 4, 5details
#50.01 s1, 2, 3, 4, 5details
#60.01 s2, 5details
#70.01 s2, 5details
#80.01 s2, 5details
#90.01 s3, 4, 5details
#100.01 s3, 4, 5details
#110.01 s3, 4, 5details
#120.01 s4, 5details
#130.01 s4, 5details
#140.01 s4, 5details
#150.01 s5details
#160.01 s5details
#170.01 s5details
#180.01 s5details
#190.01 s5details
#200.01 s5details
#210.01 s5details
#220.01 s1, 2, 3, 4, 5details
#230.01 s1, 2, 3, 4, 5details
#240.01 s5details
#250.01 s5details
#260.01 s5details
#270.01 s5details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for (int j = 0; j < rowReach[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~
input/code.cpp:104:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RowJump*>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |       for (int j = 0; j < toCheck.size(); j++) {
      |                       ~~^~~~~~~~~~~~~~~~
input/code.cpp:108:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |         for (int k = 0; k < rowReach[idx].size(); k++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:144:23: warning: comparison of integer expressions of different signedness: 'in...

Code

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

bool safe[250][250];

struct RowJump {
  int startRow;
  int endRow;
  int secondRow;
  int secondToLast;
  int rowJumps;

  RowJump(int start) {
    startRow = start;
  }

  void setEndRow(int r) {
    endRow = r;
  }

  void setSecondRow(int r) {
    secondRow = r;
  }

  void setSecondToLast(int r) {
    secondToLast = r;
  }

  void setRowJumps(int j) {
    rowJumps = j;
  }

  int getJumpCount(int startCol, int endCol) {
    int jumps = rowJumps * 2 - 1;
    if (!safe[secondRow][startCol]) {
      ++jumps;
    }
    if (!safe[secondToLast][endCol]) {
      ++jumps;
    }
    if (jumps == 1 && startCol != endCol) {
      ++jumps;
    }
    // cout << rowJumps << " " << jumps << endl;
    return jumps;
  }
};

int main() {
  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);
        }
      }
    }
  }

  // Calculate stuff
  vector<RowJump*> rowJumps[250][250];

  bool checked[250][250] = {};
  for (int i = 0; i < n; i++) {
    checked[i][i] = true;
    vector<RowJump*> toCheck;
    // cout << i << "  " << rowReach[i].size() << endl;
    for (int j = 0; j < rowReach[i].size(); j++) {
      RowJump* newJump = new RowJump(i);
      newJump->setSecondRow(rowReach[i][j]);
      newJump->setSecondToLast(i);
      newJump->setEndRow(rowReach[i][j]);
      newJump->setRowJumps(1);
      rowJumps[i][rowReach[i][j]].push_back(newJump);
      toCheck.push_back(newJump);
    }
    int round = 1;
    while (toCheck.size() > 0) {
      // When adding RowJump*, set the previous row to secondToLast and current to lastRow.
      // Do some cloning of previous row's RowJump to get secondRow.
      // If row is available from multiple sources, just add multiple RowJump* to rowJumps.
      // Don't add already checked to toCheck.
      // Get dragged to gym and take a break.
      ++round;
      vector<RowJump*> newCheck;
      for (int j = 0; j < toCheck.size(); j++) {
        int idx = toCheck[j]->endRow;
        checked[i][idx] = true;

        for (int k = 0; k < rowReach[idx].size(); k++) {
          if (checked[rowReach[idx][k]]) continue;
          RowJump* newJump = new RowJump(i);
          newJump->setSecondRow(toCheck[j]->secondRow);
          newJump->setSecondToLast(idx);
          newJump->setEndRow(rowReach[idx][k]);
          newJump->setRowJumps(round);
          rowJumps[i][rowReach[idx][k]].push_back(newJump);
          newCheck.push_back(newJump);
        }

      }
      toCheck = newCheck;
    }
  }

  // cout << "Processed data" << endl;

  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 (y1 == y2) {
      results[i] = (x1 == x2) ? 0 : 1;
      continue;
    }

    if (rowJumps[y1][y2].size() == 0) {
      results[i] = -1;
      continue;
    }

    int minJumps = 2147483647;
    // cout << rowJumps[y1][y2].size() << endl;
    for (int i = 0; i < rowJumps[y1][y2].size(); i++) {
      int jumpCount = rowJumps[y1][y2][i]->getJumpCount(x1, x2);
      if (jumpCount < minJumps) {
        minJumps = jumpCount;
      }
      if (jumpCount == rowJumps[y1][y2][i]->rowJumps * 2 - 1) break;
    }
    results[i] = minJumps;
  }

  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:

input
4 6 5
.*.***
*...**
*****.
*..*.*
...

correct output
1
0
3
3
-1

user output
(empty)

Feedback: Output is shorter than expected

Test 2

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
1
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
1
2
2
1
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
3
4
2
3
4
...

user output
(empty)

Feedback: Output is shorter than expected

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
7

user output
(empty)

Feedback: Output is shorter than expected

Test 6

Group: 2, 5

Verdict:

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

correct output
2
3
3
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 7

Group: 2, 5

Verdict:

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

correct output
2
2
2
2
3
...

user output
(empty)

Feedback: Output is shorter than expected

Test 8

Group: 2, 5

Verdict:

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

correct output
2
3
3
3
3
...

user output
(empty)

Feedback: Output is shorter than expected

Test 9

Group: 3, 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 10

Group: 3, 4, 5

Verdict:

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

correct output
2
1
3
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 11

Group: 3, 4, 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
(empty)

Feedback: Output is shorter than expected

Test 12

Group: 4, 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 13

Group: 4, 5

Verdict:

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

correct output
3
2
2
3
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 14

Group: 4, 5

Verdict:

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

correct output
2
3
1
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 15

Group: 5

Verdict:

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

correct output
3
2
2
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 16

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 17

Group: 5

Verdict:

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

correct output
3
3
2
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
(empty)

Feedback: Output is shorter than expected

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
(empty)

Feedback: Output is shorter than expected

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
(empty)

Feedback: Output is shorter than expected

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
(empty)

Feedback: Output is shorter than expected

Test 22

Group: 1, 2, 3, 4, 5

Verdict:

input
10 1 10
*
*
.
*
...

correct output
0
1
1
0
0
...

user output
(empty)

Feedback: Output is shorter than expected

Test 23

Group: 1, 2, 3, 4, 5

Verdict:

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

Feedback: Output is shorter than expected

Test 24

Group: 5

Verdict:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
(empty)

Feedback: Output is shorter than expected

Test 25

Group: 5

Verdict:

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

correct output
1
1
1
1
1
...

user output
(empty)

Feedback: Output is shorter than expected

Test 26

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Feedback: Output is shorter than expected

Test 27

Group: 5

Verdict:

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

correct output
0
0
0
0
0
...

user output
(empty)

Feedback: Output is shorter than expected