| Task: | Hypyt |
| Sender: | lukarantalainen |
| Submission time: | 2026-07-13 11:36:16 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 0 |
| subtask | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| #4 | WRONG ANSWER | 0 |
| #5 | WRONG ANSWER | 0 |
| test | verdict | time | subtask | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #2 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #3 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #4 | WRONG ANSWER | 0.00 s | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #6 | WRONG ANSWER | 0.02 s | 2, 5 | details |
| #7 | WRONG ANSWER | 0.02 s | 2, 5 | details |
| #8 | WRONG ANSWER | 0.02 s | 2, 5 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #14 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #17 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #18 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #19 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #20 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #21 | TIME LIMIT EXCEEDED | -- | 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 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #25 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #26 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #27 | TIME LIMIT EXCEEDED | -- | 5 | details |
Code
#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
struct Point {
int x;
int y;
struct HashFunction {
size_t operator()(const Point& point) const {
size_t x_hash = std::hash<int>()(point.x);
size_t y_hash = std::hash<int>()(point.y);
return x_hash ^ y_hash;
}
};
};
bool operator==(const Point a, const Point b) {
return (a.x == b.x && a.y == b.y);
}
bool operator!=(const Point a, const Point b) {
return !(a.x == b.x && a.y == b.y);
}
ostream& operator<<(ostream& out, Point point) {
out << point.x << "," << point.y;
return out;
}
int heuristic(Point a, Point b) {
return abs(a.x-b.x) + abs(a.y-b.y);
}
class TargetCompare {
const Point target;
public:
TargetCompare(Point target) : target { target } {}
bool operator()(const std::pair<Point, int>& a, const std::pair<Point, int>& b) const {
return heuristic(a.first, target) > heuristic(b.first, target);
}
};
// have to find the same column or row as the target
int find_route(const std::vector<std::string>& grid, const Point start, const Point target) {
const int n = grid.size();
const int m = grid[0].size();
auto compare = TargetCompare(target);
auto pq = priority_queue<std::pair<Point, int>, std::vector<std::pair<Point, int>>, TargetCompare>(compare);
pq.push({start, 0});
std::vector<std::vector<bool>> visited(n, std::vector<bool>(m, false));
visited[start.y][start.x] = true;
while (!pq.empty()) {
auto curr{pq.top()};
pq.pop();
if (curr.first == target) return curr.second;
for (int col{}; col < m; ++col) {
Point test{col, curr.first.y};
if (!visited[test.y][test.x] && grid[test.y][test.x] != '*') {
visited[test.y][test.x] = true;
pq.push({test, curr.second+1});
}
}
for (int row{}; row < n; ++row) {
Point test{curr.first.x, row};
if (!visited[test.y][test.x] && grid[test.y][test.x] != '*') {
visited[test.y][test.x] = true;
pq.push({test, curr.second+1});
}
}
}
return -1;
}
int main() {
iostream::ios_base::sync_with_stdio(0);
cin.tie(0);
// ifstream in("in.txt");
//cin.rdbuf(in.rdbuf());
int n, m, q;
cin >> n >> m >> q;
std::vector<std::string> grid;
for (int i{}; i < n; ++i) {
std::string line;
while (line == "") {
std::getline(std::cin, line);
}
grid.push_back(line);
}
//assert(static_cast<int>(grid.size()) == n && static_cast<int>(grid[grid.size() - 1].size()) == m);
for (int i{}; i < q; ++i) {
Point start;
Point target;
std::cin >> start.y >> start.x >> target.y >> target.x;
--start.x;
--start.y;
--target.x;
--target.y;
int result = find_route(grid, start, target);
std::cout << result << "\n";
}
return 0;
}
Test details
Test 1 (public)
Subtask: 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
Subtask: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 10 .......... .....*.... ........*. *.*....*.. ... |
| correct output |
|---|
| 1 2 1 2 2 ... |
| user output |
|---|
| 1 2 1 2 3 ... |
Feedback: Incorrect character on line 5 col 1: expected "2", got "3"
Test 3
Subtask: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 10 *...***.** *****.*... **..**.**. ..**.**.*. ... |
| correct output |
|---|
| 1 2 2 1 2 ... |
| user output |
|---|
| 1 2 3 1 2 ... |
Feedback: Incorrect character on line 3 col 1: expected "2", got "3"
Test 4
Subtask: 1, 2, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 10 ***.*.**** ********** *.******** .*.***.**. ... |
| correct output |
|---|
| 3 4 2 3 4 ... |
| user output |
|---|
| 7 4 5 5 5 ... |
Feedback: Incorrect character on line 1 col 1: expected "3", got "7"
Test 5
Subtask: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 1 .****.**** **.**..*** ********** *******..* ... |
| correct output |
|---|
| 7 |
| user output |
|---|
| 7 |
Test 6
Subtask: 2, 5
Verdict: WRONG ANSWER
| input |
|---|
| 250 250 250 .*...*.....*******..**...*....... |
| correct output |
|---|
| 2 3 3 2 2 ... |
| user output |
|---|
| 2 3 4 4 3 ... |
Feedback: Incorrect character on line 3 col 1: expected "3", got "4"
Test 7
Subtask: 2, 5
Verdict: WRONG ANSWER
| input |
|---|
| 250 250 250 ...*......**.**.*.*..**..*..**... |
| correct output |
|---|
| 2 2 2 2 3 ... |
| user output |
|---|
| 2 2 2 2 5 ... |
Feedback: Incorrect character on line 5 col 1: expected "3", got "5"
Test 8
Subtask: 2, 5
Verdict: WRONG ANSWER
| input |
|---|
| 250 250 250 **..**..****.****.*.***.***..*... |
| correct output |
|---|
| 2 3 3 3 3 ... |
| user output |
|---|
| 6 3 8 5 5 ... |
Feedback: Incorrect character on line 1 col 1: expected "2", got "6"
Test 9
Subtask: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 ...*.**.*..*.............*.*..... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 10
Subtask: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 **.**..*.*.*.******....****.*.... |
| correct output |
|---|
| 2 1 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 11
Subtask: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 .*.*.**.*****.***.*.****.**.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 12
Subtask: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *....**.***..****...*.....*...... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 13
Subtask: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 .***.*..*.***..*****....**...*... |
| correct output |
|---|
| 3 2 2 3 2 ... |
| user output |
|---|
| (empty) |
Test 14
Subtask: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *******.*****.*..*..****...***... |
| correct output |
|---|
| 2 3 1 2 2 ... |
| user output |
|---|
| (empty) |
Test 15
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *....*..*..*..**..*.........**... |
| correct output |
|---|
| 3 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 16
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..*....*..*......*.**.*.*..***... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 17
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *..*.*****.*********.****.****... |
| correct output |
|---|
| 3 3 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 18
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *********.**********.******.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 19
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 104 422 145 93 65 ... |
| user output |
|---|
| (empty) |
Test 20
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..****************************... |
| correct output |
|---|
| 57 155 38 65 98 ... |
| user output |
|---|
| (empty) |
Test 21
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 498 498 498 498 498 ... |
| user output |
|---|
| (empty) |
Test 22
Subtask: 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
Subtask: 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
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 1 200000 * . * . ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 25
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1 250 200000 *.*.*...*.*.**.***..**.*.*..**... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 26
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ................................. |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 27
Subtask: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ******************************... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| (empty) |
