Submission details
Task:Hypyt
Sender:Tmotomaster
Submission time:2025-11-04 21:13:37 +0200
Language:C++ (C++20)
Status:READY
Result:40
Feedback
groupverdictscore
#1ACCEPTED10
#20
#3ACCEPTED15
#4ACCEPTED15
#50
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3, 4, 5details
#2ACCEPTED0.01 s1, 2, 3, 4, 5details
#3ACCEPTED0.01 s1, 2, 3, 4, 5details
#4ACCEPTED0.01 s1, 2, 3, 4, 5details
#5ACCEPTED0.01 s1, 2, 3, 4, 5details
#6--2, 5details
#7--2, 5details
#8--2, 5details
#9ACCEPTED0.20 s3, 4, 5details
#10ACCEPTED0.21 s3, 4, 5details
#11ACCEPTED0.22 s3, 4, 5details
#12ACCEPTED0.26 s4, 5details
#13ACCEPTED0.28 s4, 5details
#14ACCEPTED0.33 s4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19ACCEPTED0.24 s5details
#200.85 s5details
#21ACCEPTED0.20 s5details
#22ACCEPTED0.01 s1, 2, 3, 4, 5details
#23ACCEPTED0.01 s1, 2, 3, 4, 5details
#24ACCEPTED0.48 s5details
#25ACCEPTED0.18 s5details
#26--5details
#27ACCEPTED0.21 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:141: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("random.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];

  for (int i = 0; i < n; i++) {
    bool checked[250] = {};
    checked[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[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;
    }
  }

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

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:

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

correct output
57
155
38
65
98
...

user output
(empty)

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