| Task: | Hypyt |
| Sender: | ma100 |
| Submission time: | 2025-11-03 18:18:15 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 10 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | RUNTIME ERROR | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| #4 | TIME LIMIT EXCEEDED | 0 |
| #5 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.12 s | 1, 2, 3, 4, 5 | details |
| #2 | ACCEPTED | 0.12 s | 1, 2, 3, 4, 5 | details |
| #3 | ACCEPTED | 0.12 s | 1, 2, 3, 4, 5 | details |
| #4 | ACCEPTED | 0.12 s | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.12 s | 1, 2, 3, 4, 5 | details |
| #6 | RUNTIME ERROR | 0.01 s | 2, 5 | details |
| #7 | RUNTIME ERROR | 0.01 s | 2, 5 | details |
| #8 | RUNTIME ERROR | 0.01 s | 2, 5 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #10 | ACCEPTED | 0.62 s | 3, 4, 5 | details |
| #11 | ACCEPTED | 0.32 s | 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 | RUNTIME ERROR | 0.01 s | 5 | details |
| #16 | RUNTIME ERROR | 0.01 s | 5 | details |
| #17 | RUNTIME ERROR | 0.01 s | 5 | details |
| #18 | RUNTIME ERROR | 0.01 s | 5 | details |
| #19 | RUNTIME ERROR | 0.01 s | 5 | details |
| #20 | RUNTIME ERROR | 0.01 s | 5 | details |
| #21 | RUNTIME ERROR | 0.01 s | 5 | details |
| #22 | ACCEPTED | 0.12 s | 1, 2, 3, 4, 5 | details |
| #23 | ACCEPTED | 0.12 s | 1, 2, 3, 4, 5 | details |
| #24 | ACCEPTED | 0.20 s | 5 | details |
| #25 | ACCEPTED | 0.20 s | 5 | details |
| #26 | RUNTIME ERROR | 0.01 s | 5 | details |
| #27 | RUNTIME ERROR | 0.01 s | 5 | details |
Code
#include <bits/stdc++.h>
using namespace std;
class Node
{
public:
uint16_t id;
uint64_t depth;
Node(uint16_t i, uint64_t d)
{
id = i;
depth = d;
}
};
uint16_t id(const uint8_t x, const uint8_t y, const uint8_t max_y)
{
return x * max_y + y;
}
optional<uint64_t> path_find(
uint16_t start_i,
uint16_t end_i,
const vector<vector<uint16_t>> &opts,
uint8_t x_len,
uint8_t y_len,
unordered_map<uint32_t, uint64_t> &cache)
{
if (start_i == end_i)
{
return 0;
}
uint32_t cache_key = (uint32_t)start_i | ((uint32_t)end_i << 0x10);
if (cache.find(cache_key) != cache.end())
{
return cache[cache_key];
}
queue<Node> search_queue = {};
search_queue.push(Node(start_i, 0));
vector<uint8_t> visited(x_len * y_len, false);
visited[start_i] = true;
while (!search_queue.empty())
{
Node current = search_queue.front();
search_queue.pop();
auto opt = opts[current.id];
for (uint32_t el : opt)
{
if (current.id == el)
{
continue;
}
uint64_t value = current.depth + 1;
if (el == end_i)
{
cache[cache_key] = value;
return value;
}
if (!visited[el])
{
search_queue.push(Node(el, value));
uint32_t cache_key = (uint32_t)start_i | ((uint32_t)el << 0x10);
cache[cache_key] = value;
visited[el] = true;
}
}
}
return {};
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
uint32_t q;
cin >> n >> m >> q;
vector<vector<uint8_t>> grid(n, vector<uint8_t>(m, false));
string line;
for (uint8_t y = 0; y < n; y++)
{
cin >> line;
for (uint8_t x = 0; x < m; x++)
{
grid[y][x] = line[x] == '.';
}
line.clear();
}
vector<vector<uint16_t>> options_per_row(n, vector<uint16_t>());
options_per_row.reserve(n * m);
vector<vector<uint16_t>> options_per_col(m, vector<uint16_t>());
options_per_col.reserve(n * m);
for (uint16_t y = 0; y < n; y++)
{
auto row = grid[y];
for (uint16_t x = 0; x < m; x++)
{
if (row[x])
{
uint16_t i = id(x, y, n);
options_per_row[y].push_back(i);
options_per_col[x].push_back(i);
}
}
}
vector<vector<uint16_t>> options(n * m, vector<uint16_t>());
options.reserve(n * n * m * m);
for (uint16_t y = 0; y < n; y++)
{
for (uint16_t x = 0; x < m; x++)
{
uint16_t i = id(x, y, n);
options[i].reserve(options_per_col[x].size() + options_per_row[y].size());
for (auto opts : {&options_per_col[x], &options_per_row[y]})
{
options[i].insert(options[i].end(), opts->begin(), opts->end());
}
}
}
unordered_map<uint32_t, uint64_t> cache;
cache.reserve(0x1000000);
for (uint32_t i = 0; i < q; i++)
{
int y1, x1, y2, x2;
cin >> y1 >> x1 >> y2 >> x2;
y1--;
x1--;
y2--;
x2--;
optional<uint64_t> res = path_find(id(x1, y1, n), id(x2, y2, n), options, m, n, cache);
if (res.has_value())
{
cout << res.value() << '\n';
}
else
{
cout << "-1\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: RUNTIME ERROR
| input |
|---|
| 250 250 250 .*...*.....*******..**...*....... |
| correct output |
|---|
| 2 3 3 2 2 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 7
Group: 2, 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 250 ...*......**.**.*.*..**..*..**... |
| correct output |
|---|
| 2 2 2 2 3 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 8
Group: 2, 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 250 **..**..****.****.*.***.***..*... |
| correct output |
|---|
| 2 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 9
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 ...*.**.*..*.............*.*..... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
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: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *....**.***..****...*.....*...... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 13
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 .***.*..*.***..*****....**...*... |
| correct output |
|---|
| 3 2 2 3 2 ... |
| user output |
|---|
| (empty) |
Test 14
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| 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) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 16
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ..*....*..*......*.**.*.*..***... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 17
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 *..*.*****.*********.****.****... |
| correct output |
|---|
| 3 3 2 2 2 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 18
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 *********.**********.******.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 19
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 104 422 145 93 65 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 20
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ..****************************... |
| correct output |
|---|
| 57 155 38 65 98 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 21
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 498 498 498 498 498 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
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: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ................................. |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
Test 27
Group: 5
Verdict: RUNTIME ERROR
| input |
|---|
| 250 250 200000 ******************************... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| (empty) |
Error:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
