| Task: | Hypyt |
| Sender: | rottis |
| Submission time: | 2025-10-30 11:07:11 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 60 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | ACCEPTED | 20 |
| #3 | ACCEPTED | 15 |
| #4 | ACCEPTED | 15 |
| #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 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #6 | ACCEPTED | 0.01 s | 2, 5 | details |
| #7 | ACCEPTED | 0.01 s | 2, 5 | details |
| #8 | ACCEPTED | 0.01 s | 2, 5 | details |
| #9 | ACCEPTED | 0.12 s | 3, 4, 5 | details |
| #10 | ACCEPTED | 0.11 s | 3, 4, 5 | details |
| #11 | ACCEPTED | 0.13 s | 3, 4, 5 | details |
| #12 | ACCEPTED | 0.12 s | 4, 5 | details |
| #13 | ACCEPTED | 0.13 s | 4, 5 | details |
| #14 | ACCEPTED | 0.14 s | 4, 5 | details |
| #15 | ACCEPTED | 0.18 s | 5 | details |
| #16 | ACCEPTED | 0.20 s | 5 | details |
| #17 | ACCEPTED | 0.23 s | 5 | details |
| #18 | ACCEPTED | 0.25 s | 5 | details |
| #19 | ACCEPTED | 0.67 s | 5 | details |
| #20 | ACCEPTED | 0.96 s | 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 | ACCEPTED | 0.06 s | 5 | details |
| #25 | ACCEPTED | 0.06 s | 5 | details |
| #26 | ACCEPTED | 0.16 s | 5 | details |
| #27 | ACCEPTED | 0.06 s | 5 | details |
Code
#include <iostream>
#include <unordered_map>
#include <string.h> // memset
#include <vector>
typedef unsigned char uchar;
unsigned short height, width;
unsigned long query_count;
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(NULL);
std::vector<uchar> rows[250];
std::vector<uchar> columns[250];
// what is connected (and not connected) to what?
// speeds up calculations resulting in -1
// index with column_index or x
int networks[250];
memset(&networks, -1, 250 * sizeof(int));
int cur_network_num = 0;
std::cin >> height >> width >> query_count;
for (unsigned short i = 0; i < height; i++) {
char buf[251];
std::cin >> buf;
for (int j = 0; j < width; j++) {
if (buf[j] == '.') {
rows[i].push_back(j);
columns[j].push_back(i);
//std::cout << "Connect row idx " << i << " to column idx " << j << std::endl;
}
}
}
for (unsigned long i = 0; i < query_count; i++) {
unsigned short start_y, start_x, end_y, end_x;
std::cin >> start_y >> start_x >> end_y >> end_x;
start_y--; start_x--; end_y--; end_x--;
if (start_x == end_x && start_y == end_y) {
std::cout << "0\n";
continue;
}
if (start_x == end_x || start_y == end_y) {
std::cout << "1\n";
continue;
}
// if both are -1, neither are set already, we can't do anything with that info
// if one is not -1, we know they are not in the same network or else the
// code that set the other to not be -1 would have set them both to not be -1
if (networks[start_x] != networks[end_x] && (networks[start_x] != -1 || networks[end_x] != -1)) {
std::cout << "-1\n";
continue;
}
bool available_rows[250];
bool available_cols[250];
memset(&available_rows, 0, height);
memset(&available_cols, 0, width);
std::vector<uchar> just_added_rows;
std::vector<uchar> just_added_cols;
just_added_rows.reserve(height);
just_added_cols.reserve(width);
//memset(&just_added_rows, 0, height);
//memset(&just_added_cols, 0, width);
just_added_rows.push_back(start_y);
just_added_cols.push_back(start_x);
std::vector<uchar> cols_to_add;
cols_to_add.reserve(width);
for (int cost = 2;; cost++) {
// set to false when modifying rows_to_add and cols_to_add, if no modifications are made then break out with -1
bool no_solution = true;
for (uchar row_idx : just_added_rows) {
if (available_rows[row_idx]) { continue; }
//std::cout << "Row " << (int) row_idx << std::endl;
//just_added_rows[row_idx] = false;
available_rows[row_idx] = true;
for (uchar col_idx : rows[row_idx]) {
if (col_idx == end_x) {
std::cout << cost << '\n'; goto complete;
}
//std::cout << "Add col " << (int) col_idx << std::endl;
cols_to_add.push_back(col_idx);
no_solution = false;
}
}
just_added_rows.clear();
for (uchar col_idx : just_added_cols) {
if (available_cols[col_idx]) { continue; }
//std::cout << "Col " << (int) col_idx << std::endl;
//just_added_cols[col_idx] = false;
available_cols[col_idx] = true;
for (uchar row_idx : columns[col_idx]) {
if (row_idx == end_y) {
std::cout << cost << '\n'; goto complete;
}
//std::cout << "Add row " << (int) row_idx << std::endl;
just_added_rows.push_back(row_idx);
no_solution = false;
}
}
just_added_cols.clear();
if (no_solution) {
std::cout << "-1\n";
// store network map for use in later calls
for (uchar i = 0; i < 250; i++) {
if (available_cols[i]) {
networks[i] = cur_network_num;
}
}
cur_network_num++;
goto complete;
}
while (cols_to_add.size()) {
just_added_cols.push_back(cols_to_add.back());
cols_to_add.pop_back();
}
}
complete:
continue;
}
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: 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: ACCEPTED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 104 422 145 93 65 ... |
| user output |
|---|
| 104 422 145 93 65 ... |
Test 20
Group: 5
Verdict: ACCEPTED
| input |
|---|
| 250 250 200000 ..****************************... |
| correct output |
|---|
| 57 155 38 65 98 ... |
| user output |
|---|
| 57 155 38 65 98 ... |
Test 21
Group: 5
Verdict: TIME LIMIT EXCEEDED
| 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 ... |
