| Task: | Hypyt |
| Sender: | rottis |
| Submission time: | 2025-10-28 00:55:08 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | TIME LIMIT EXCEEDED | 0 |
| #2 | TIME LIMIT EXCEEDED | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| #4 | TIME LIMIT EXCEEDED | 0 |
| #5 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #2 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #3 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #4 | TIME LIMIT EXCEEDED | -- | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #6 | ACCEPTED | 0.04 s | 2, 5 | details |
| #7 | ACCEPTED | 0.04 s | 2, 5 | details |
| #8 | ACCEPTED | 0.05 s | 2, 5 | details |
| #9 | RUNTIME ERROR | 0.02 s | 3, 4, 5 | details |
| #10 | RUNTIME ERROR | 0.02 s | 3, 4, 5 | details |
| #11 | RUNTIME ERROR | 0.02 s | 3, 4, 5 | details |
| #12 | RUNTIME ERROR | 0.03 s | 4, 5 | details |
| #13 | RUNTIME ERROR | 0.02 s | 4, 5 | details |
| #14 | RUNTIME ERROR | 0.02 s | 4, 5 | details |
| #15 | RUNTIME ERROR | 0.02 s | 5 | details |
| #16 | RUNTIME ERROR | 0.02 s | 5 | details |
| #17 | RUNTIME ERROR | 0.02 s | 5 | details |
| #18 | RUNTIME ERROR | 0.02 s | 5 | details |
| #19 | RUNTIME ERROR | 0.02 s | 5 | details |
| #20 | RUNTIME ERROR | 0.02 s | 5 | details |
| #21 | RUNTIME ERROR | 0.02 s | 5 | details |
| #22 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #23 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #24 | RUNTIME ERROR | 0.02 s | 5 | details |
| #25 | RUNTIME ERROR | 0.02 s | 5 | details |
| #26 | RUNTIME ERROR | 0.02 s | 5 | details |
| #27 | RUNTIME ERROR | 0.02 s | 5 | details |
Compiler report
input/code.cpp: In function 'int algorithm(uint (*)[250], vec2, vec2)':
input/code.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'uint' {aka 'unsigned int'} [-Wsign-compare]
86 | for (int x = 0; x < wid; x++) {
| ~~^~~~~
input/code.cpp:99:27: warning: comparison of integer expressions of different signedness: 'int' and 'uint' {aka 'unsigned int'} [-Wsign-compare]
99 | for (int y = 0; y < hgt; y++) {
| ~~^~~~~Code
#include <iostream>
#include <string>
#include <unordered_set>
#include <queue>
#define parse(char) (char == '.')
#define Queue std::priority_queue<Node, std::vector<Node>, Compare>
typedef unsigned int uint;
typedef struct vec2 {
int x;
int y;
} vec2;
inline long long to_long(vec2 pos) {
long long retval;
retval = pos.x;
retval <<= 32;
retval |= pos.y;
return retval;
}
class Node {
public:
int cost;
int heuristic;
vec2 pos;
Node(int cost_, int heuristic_, vec2 pos_) {
cost = cost_;
heuristic = heuristic_;
pos = pos_;
}
};
class Compare
{
public:
bool operator() (Node a, Node b)
{
return a.cost + a.heuristic > b.cost + b.heuristic;
}
};
const uint BSIZE = 250;
inline vec2 vec2_add(vec2 a, vec2 b) {
return vec2 { a.x + b.x, a.y + b.y};
}
inline bool vec2_neq(vec2 a, vec2 b) {
return (a.x != b.x || a.y != b.y);
}
inline bool vec2_eq(vec2 a, vec2 b) {
return (a.x == b.x && a.y == b.y);
}
uint hgt, wid;
int heuristic(vec2 pos, vec2 end) {
if (vec2_eq(pos, end)) { return 0; }
if (pos.x == end.x || pos.y == end.y) {
return 1;
}
return 2;
}
int algorithm(uint board[BSIZE][BSIZE], vec2 start, vec2 end) {
Queue queue;
std::unordered_set<long long> already_visited;
queue.push(Node(0, heuristic(start, end), start));
//std::cout << "s: " << start.x << ' ' << start.y << ", e: " << end.x << ' ' << end.y << ", heuristic: " << heuristic(start, end) << std::endl;
while (!queue.empty()) {
Node cur = queue.top();
//std::cout << "cpos: (" << cur.pos.x << ", " << cur.pos.y << "), cost: " << cur.cost << ", heuristic: " << cur.heuristic << std::endl;
queue.pop();
if (vec2_eq(cur.pos, end)) {
return cur.cost;
}
for (int x = 0; x < wid; x++) {
//std::cout << "cx: " << x << std::endl;
vec2 pos = { x, cur.pos.y };
//std::cout << (!board[pos.y][pos.x]) << (cur.pos.x == x) << (already_visited.count(to_long(pos)) > 0) << std::endl;
if (!board[pos.y][pos.x]) { continue; }
if (cur.pos.x == x) { continue; }
if (already_visited.count(to_long(pos)) > 0) { continue; }
queue.push(Node(cur.cost + 1, heuristic(pos, end), pos));
}
for (int y = 0; y < hgt; y++) {
//std::cout << "cy: " << y << std::endl;
vec2 pos = { cur.pos.x, y };
//std::cout << (!board[pos.y][pos.x]) << (cur.pos.y == y) << (already_visited.count(to_long(pos)) > 0) << std::endl;
if (!board[pos.y][pos.x]) { continue; }
if (cur.pos.y == y) { continue; }
if (already_visited.count(to_long(pos)) > 0) { continue; }
queue.push(Node(cur.cost + 1, heuristic(pos, end), pos));
}
}
return -1;
}
int main() {
uint q;
std::cin >> hgt >> wid >> q;
uint board[BSIZE][BSIZE];
for (uint i = 0; i < hgt; i++) {
uint row[BSIZE] = {};
*board[i] = *row;
}
char buf[BSIZE+1];
for (uint y = 0; y < hgt; y++) {
std::cin >> buf;
for (uint x = 0; x < wid; x++) {
board[y][x] = parse(buf[x]);
}
}
/* board[y][x] contains whether that cell is valid to move to */
/*for (int i = 0; i < BSIZE; i++) {
for (int j = 0; j < BSIZE; j++) {
std::cout << board[i][j];
}
std::cout << std::endl;
}*/
vec2 configurations[40000];
for (uint i = 0; i < q; i++) {
int startx, starty, endx, endy;
std::cin >> starty >> startx >> endy >> endx;
vec2 start = { startx - 1, starty - 1 };
vec2 end = { endx - 1, endy - 1 };
configurations[2 * i] = start;
configurations[2 * i + 1] = end;
}
for (uint i = 0; i < q; i++) {
std::cout << algorithm(board, configurations[2*i], configurations[2*i+1]) << std::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: TIME LIMIT EXCEEDED
| input |
|---|
| 10 10 10 ***.*.**** ********** *.******** .*.***.**. ... |
| correct output |
|---|
| 3 4 2 3 4 ... |
| user output |
|---|
| (empty) |
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: RUNTIME ERROR
| input |
|---|
| 40 40 200000 ...*.**.*..*.............*.*..... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 10
Group: 3, 4, 5
Verdict: RUNTIME ERROR
| input |
|---|
| 40 40 200000 **.**..*.*.*.******....****.*.... |
| correct output |
|---|
| 2 1 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 11
Group: 3, 4, 5
Verdict: RUNTIME ERROR
| input |
|---|
| 40 40 200000 .*.*.**.*****.***.*.****.**.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 12
Group: 4, 5
Verdict: RUNTIME ERROR
| input |
|---|
| 80 80 200000 *....**.***..****...*.....*...... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 13
Group: 4, 5
Verdict: RUNTIME ERROR
| input |
|---|
| 80 80 200000 .***.*..*.***..*****....**...*... |
| correct output |
|---|
| 3 2 2 3 2 ... |
| user output |
|---|
| (empty) |
Test 14
Group: 4, 5
Verdict: RUNTIME ERROR
| input |
|---|
| 80 80 200000 *******.*****.*..*..****...***... |
| correct output |
|---|
| 2 3 1 2 2 ... |
| user output |
|---|
| (empty) |
Test 15
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 *....*..*..*..**..*.........**... |
| correct output |
|---|
| 3 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 16
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ..*....*..*......*.**.*.*..***... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 17
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 *..*.*****.*********.****.****... |
| correct output |
|---|
| 3 3 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 18
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 *********.**********.******.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 19
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 104 422 145 93 65 ... |
| user output |
|---|
| (empty) |
Test 20
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ..****************************... |
| correct output |
|---|
| 57 155 38 65 98 ... |
| user output |
|---|
| (empty) |
Test 21
Group: 5
Verdict: RUNTIME ERROR
| 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: RUNTIME ERROR
| input |
|---|
| 250 1 200000 * . * . ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 25
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 1 250 200000 *.*.*...*.*.**.***..**.*.*..**... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 26
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ................................. |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 27
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ******************************... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| (empty) |
