Submission details
Task:Hypyt
Sender:rendes
Submission time:2025-11-04 19:47:07 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#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
#40.01 s1, 2, 3, 4, 5details
#50.01 s1, 2, 3, 4, 5details
#6ACCEPTED0.02 s2, 5details
#7ACCEPTED0.02 s2, 5details
#8ACCEPTED0.01 s2, 5details
#9ACCEPTED0.18 s3, 4, 5details
#10ACCEPTED0.18 s3, 4, 5details
#110.19 s3, 4, 5details
#12ACCEPTED0.19 s4, 5details
#13ACCEPTED0.20 s4, 5details
#140.22 s4, 5details
#15ACCEPTED0.25 s5details
#16ACCEPTED0.25 s5details
#17ACCEPTED0.26 s5details
#180.35 s5details
#190.21 s5details
#200.25 s5details
#210.20 s5details
#22ACCEPTED0.01 s1, 2, 3, 4, 5details
#23ACCEPTED0.01 s1, 2, 3, 4, 5details
#24ACCEPTED0.12 s5details
#25ACCEPTED0.12 s5details
#26ACCEPTED0.24 s5details
#27ACCEPTED0.12 s5details

Compiler report

input/code.cpp: In function 'void getNums(std::string, int**, uint)':
input/code.cpp:21:41: warning: comparison of integer expressions of different signedness: 'uint' {aka 'unsigned int'} and 'int' [-Wsign-compare]
   21 |   while (getline(iss, s, ' ') && vcount != ccount) {
      |                                  ~~~~~~~^~~~~~~~~
input/code.cpp: In member function 'int Grid::solve(uint8_t, uint8_t, uint8_t, uint8_t)':
input/code.cpp:174:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  174 |       if (xopt[ypos].count(dx))
      |       ^~
input/code.cpp:176:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  176 |         return 3;
      |         ^~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:220:14: warning: unused variable 'sc' [-Wunused-variable]
  220 |     uint16_t sc = grid.solve(w - 1, h - 1, z - 1, c - 1);
      |              ^~
input/code.cpp:196:8: warning: unused variable 'qco...

Code

#include <cstdint>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define MONS 65535
#define UNIN 65534
#define uin uint8_t

void getNums(const std::string in, int **values, uint vcount) {
  int ccount = 0;
  std::istringstream iss(in);
  std::string s;
  while (getline(iss, s, ' ') && vcount != ccount) {
    *values[ccount] = std::stoi(s);
    ccount++;
  }
}

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

struct Grid {
  std::unordered_map<uint8_t, std::unordered_set<uint8_t>> xopt, yopt;
  std::unordered_map<uint32_t, int16_t> cache;
  uint8_t w, h;
  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); }
  inline uint32_t packCoords(uin sx, uin sy, uin dx, uin dy) {
    return ((uint32_t)sx << 24) | ((uint32_t)sy << 16) | ((uint32_t)dx << 8) |
           (uint32_t)dy;
  }

  int solveslow(uin sx, uin sy, uin dx, uin dy) {
    std::unordered_set<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()) {
      cindices = std::move(nindices);

      for (auto po : cindices) {
        int found = -1;
        ivec2 p = getCoords(po);
        for (auto xpos : xopt[p.y]) {
          if (vx.count(xpos))
            continue;
          if (true) {
            if (yopt[xpos].count(sy))
              return step + 2;

            if (step == -1) {

              for (auto yposs : yopt[xpos]) {
                if (xopt[yposs].count(sx))
                  found = step + 3;
              }
            }
          }
          nindices.push_back(getIndex(xpos, p.y));
        }
        // xopt.erase(p.y);

        for (auto ypos : yopt[p.x]) {
          if (vy.count(ypos))
            continue;
          if (true) {
            if (xopt[ypos].count(sx))
              return step + 2;

            if (step == -1) {
              for (auto xposs : xopt[ypos]) {
                if (yopt[xposs].count(sy)) {
                  found = step + 3;
                }
              }
            }
          }
          nindices.push_back(getIndex(p.x, ypos));
        }
        if (found != -1)
          return found;

        // yopt.erase(p.x);
        vx.insert(p.x);
        vy.insert(p.y);
      }
      cindices.clear();
      step++;
    }

    return -1;
  }

  int solve(uin sx, uin sy, uin dx,
            uin dy) { // idk why i'm doing it like this smh. pwease work
    uint32_t mcoords = packCoords(sx, sy, dx, dy);
    if (auto sc = cache.find(mcoords); sc != cache.end())
      return sc->second;

    if (dx == sx && dy == sy) {
      cache[mcoords] = 0;
      return 0;
    } else if (dx == sx || dy == sy) {
      cache[mcoords] = 1;
      return 1;
    }
    if (xopt[sy].size() == 1 && yopt[sx].size() == 1) {
      cache[mcoords] = -1;
      return -1;
    }
    if (yopt[dx].size() == 1 && xopt[dy].size() == 1) {
      cache[mcoords]=-1;
      return -1;
    }
    if (xopt[sy].count(dx)) {
      cache[mcoords]=2;
      return 2;
    }
    if (yopt[sx].count(dy)) {
      cache[mcoords]=2;
      return 2;
    }

    for (auto xpos : xopt[sy]) {
      if (yopt[xpos].count(dy)) {
	cache[mcoords]=3;
        return 3;
      }
    }
    for (auto ypos : yopt[sx]) {
      if (xopt[ypos].count(dx))
	cache[mcoords]=3;
        return 3;
    }
    uint16_t steps = solveslow(sx, sy, dx, dy);
    cache[mcoords]=steps;
    return steps;
  }
};

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

  int w, h, c, z;
  int **vals;
  vals = new int *[4];
  vals[0] = &h;
  vals[1] = &w;
  vals[2] = &c;
  vals[3] = &z;

  uint qcount = c;

  std::string line;

  std::getline(std::cin, line);
  getNums(line, vals, 3);

  Grid grid;
  grid.cache.reserve(200000);
  grid.w = w;
  grid.h = h;

  for (int i = 0; i < h && std::getline(std::cin, line); i++) {
    if (line.size() == 0)
      continue;
    for (int x = 0; x < w; x++) {
      if (line[x] == 46) {
        grid.yopt[x].insert(i);
        grid.xopt[i].insert(x);
      }
    }
  }
  for (int i = 0; std::getline(std::cin, line); i++) {
    getNums(line, vals, 4);
    uint16_t sc = grid.solve(w - 1, h - 1, z - 1, c - 1);
    std::cout << grid.solve(w - 1, h - 1, z - 1, c - 1) << "\n";
  }

  // grid.print();
}

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:

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

correct output
3
4
2
3
4
...

user output
3
3
2
3
3
...

Feedback: Incorrect character on line 2 col 1: expected "4", got "3"

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

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

correct output
7

user output
3

Feedback: Incorrect character on line 1 col 1: expected "7", got "3"

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:

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

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 75 col 1: expected "4", got "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:

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

correct output
2
3
1
2
2
...

user output
2
3
1
2
2
...

Feedback: Incorrect character on line 82466 col 1: expected "4", got "3"

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:

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

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 441 col 1: expected "4", got "3"

Test 19

Group: 5

Verdict:

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

correct output
104
422
145
93
65
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 1 col 1: expected "104", got "3"

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 1 col 1: expected "57", got "3"

Test 21

Group: 5

Verdict:

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

correct output
498
498
498
498
498
...

user output
3
3
3
3
3
...

Feedback: Incorrect character on line 1 col 1: expected "498", got "3"

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