Submission details
Task:Hypyt
Sender:rottis
Submission time:2025-10-30 02:29:33 +0200
Language:C++ (C++17)
Status:READY
Result:60
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED20
#3ACCEPTED15
#4ACCEPTED15
#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
#4ACCEPTED0.01 s1, 2, 3, 4, 5details
#5ACCEPTED0.01 s1, 2, 3, 4, 5details
#6ACCEPTED0.01 s2, 5details
#7ACCEPTED0.01 s2, 5details
#8ACCEPTED0.01 s2, 5details
#9ACCEPTED0.13 s3, 4, 5details
#10ACCEPTED0.14 s3, 4, 5details
#11ACCEPTED0.16 s3, 4, 5details
#12ACCEPTED0.15 s4, 5details
#13ACCEPTED0.16 s4, 5details
#14ACCEPTED0.19 s4, 5details
#15ACCEPTED0.23 s5details
#16ACCEPTED0.26 s5details
#17ACCEPTED0.31 s5details
#18ACCEPTED0.39 s5details
#19--5details
#20--5details
#21--5details
#22ACCEPTED0.01 s1, 2, 3, 4, 5details
#23ACCEPTED0.01 s1, 2, 3, 4, 5details
#24ACCEPTED0.06 s5details
#25ACCEPTED0.06 s5details
#26ACCEPTED0.21 s5details
#27ACCEPTED0.06 s5details

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

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

    unsigned short start_y_arr[200000];
    unsigned short start_x_arr[200000];
    unsigned short end_y_arr[200000];
    unsigned short end_x_arr[200000];

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

        start_y_arr[i] = start_y;
        start_x_arr[i] = start_x;
        end_y_arr[i] = end_y;
        end_x_arr[i] = end_x;
    }


    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_y_arr[i];
        start_x = start_x_arr[i];
        end_y = end_y_arr[i];
        end_x = end_x_arr[i];


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

        bool available_rows[250];
        bool available_cols[250];

        memset(&available_rows, 0, height);
        memset(&available_cols, 0, width);

        bool just_added_rows[250];
        bool just_added_cols[250];

        memset(&just_added_rows, 0, height);
        memset(&just_added_cols, 0, width);

        just_added_cols[start_x] = true;
        just_added_rows[start_y] = true;

        std::vector<uchar> cols_to_add;
        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 = 0; row_idx < width; row_idx++) {
                if (available_rows[row_idx] || !just_added_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;
                }
            }

            for (uchar col_idx = 0; col_idx < height; col_idx++) {
                if (available_cols[col_idx] || !just_added_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[row_idx] = true;
                    no_solution = false;
                }
            }

            if (no_solution) { std::cout << "-1\n"; goto complete; }

            while (cols_to_add.size()) {
                just_added_cols[cols_to_add.back()] = true;
                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:

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

correct output
104
422
145
93
65
...

user output
(empty)

Test 20

Group: 5

Verdict:

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

correct output
57
155
38
65
98
...

user output
(empty)

Test 21

Group: 5

Verdict:

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