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

Compiler report

input/code.cpp: In function 'int solveslow(uint8_t, uint8_t, uint8_t, uint8_t)':
input/code.cpp:64:11: warning: unused variable 'found' [-Wunused-variable]
   64 |       int found = -1;
      |           ^~~~~

Code

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

#define row bitset<250>
#define uin uint8_t

static int h, w, qc;
static std::array<std::bitset<250>, 250> xopt, yopt;

inline bool doShare(row &s1, row &s2) {
  row sr = s1 & s2;
  return sr.count();
}

struct ivec2 {
  uin x, y = 0;
  ivec2(int x, int y) : x(x), y(y) {}
  ivec2() {}
  ivec2 operator+(const ivec2 &other) const {
    return ivec2(x + other.x, y + other.y);
  }
  ivec2 operator*(const int &value) const {
    return ivec2(x * value, y * value);
  }
  ivec2 operator/(const int &value) const {
    return ivec2(x / value, y / value);
  }
  friend std::ostream &operator<<(std::ostream &os, const ivec2 &v) {
    return os << "(" << v.x << ", " << v.y << ")";
  }

  bool operator<(const ivec2 &other) const {
    return (x < other.x) || (x == other.x && y < other.y);
  }
  bool operator>(const ivec2 &other) const {
    return (x > other.x) || (x == other.x && y > other.y);
  }
  bool operator<=(const ivec2 &other) const {
    return *this < other || *this == other;
  }
  bool operator>=(const ivec2 &other) const {
    return *this > other || *this == other;
  }
  bool operator==(const ivec2 &other) const {
    return (x == other.x && y == other.y) ? true : false;
  }
};

inline uint16_t getIndex(uint16_t x, uint16_t y) { return y * w + x; }
inline ivec2 getCoords(uint16_t index) { return ivec2(index % w, index / w); }
int solveslow(uin sx, uin sy, uin dx, uin dy) {
  std::vector<uint8_t> vx,
      vy; /// this isn't going to be any faster than the prev one, is it?
 
  std::vector<uint16_t> nindices; // step and pos
  std::vector<uint16_t> cindices;
  nindices.push_back(getIndex(dx, dy));
  int step = 1;
 
  while (!nindices.empty()) {
    std::swap(nindices,cindices);
 
    for (auto po : cindices) {
      int found = -1;
      ivec2 p = getCoords(po);
 
      for (int fi = 0; fi < 250; fi++) {
        if (xopt[p.y][fi]) {
          if (yopt[fi][sy])
            return step + 2;
	  nindices.push_back(getIndex(fi, p.y));
        }
        if (yopt[p.x][fi]) {
          if (xopt[fi][sx])
            return step + 2;
          nindices.push_back(getIndex(p.x,fi));
          
        }
      }
      vx.push_back(p.x);
      vy.push_back(p.y);
    }
    cindices.clear();
    step++;
  }
 
  return -1;
}

int solve(int sx, int sy, int dx, int dy) {
  if (dx == sx && dy == sy)
    return 0;
  else if (dx == sx || dy == sy)
    return 1;

  if (xopt[sy].count() == 1 && yopt[sx].count() == 1)
    return -1;
  if (yopt[dx].count() == 1 && xopt[dy].count() == 1)
    return -1;

  if (yopt[sx][dy])
    return 2;
  if (xopt[sy][dx])
    return 2;

  if ((xopt[sy] & xopt[dy]).count())
    return 3;

  if ((yopt[sx] & yopt[dx]).count())
    return 3;
  
  return solveslow(sx, sy, dx, dy);
}

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

  cin >> h >> w >> qc;

  string line;
  getline(cin, line);

  for (int y = 0; y < h && std::getline(cin, line); y++) {
    if (line.size() == 0)
      continue;
    for (int x = 0; x < w; x++) {
      if (line[x] == 46) {
        xopt[y][x] = 1;
        yopt[x][y] = 1;
      }
    }
  }
  int sx, sy, dx, dy;
  for (int i = 0; i < qc; i++) {
    cin >> sy >> sx >> dy >> dx;
    sx--;
    sy--;
    dx--;
    dy--;
    std::cout << solve(sx, sy, dx, dy) << "\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: 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:

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

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