Submission details
Task:Hypyt
Sender:rottis
Submission time:2025-10-30 00:33:05 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4, 5details
#2ACCEPTED0.00 s1, 2, 3, 4, 5details
#3ACCEPTED0.00 s1, 2, 3, 4, 5details
#4ACCEPTED0.00 s1, 2, 3, 4, 5details
#50.00 s1, 2, 3, 4, 5details
#6ACCEPTED0.01 s2, 5details
#7ACCEPTED0.01 s2, 5details
#8ACCEPTED0.01 s2, 5details
#9ACCEPTED0.63 s3, 4, 5details
#10ACCEPTED0.75 s3, 4, 5details
#11ACCEPTED0.81 s3, 4, 5details
#12ACCEPTED0.73 s4, 5details
#13ACCEPTED0.96 s4, 5details
#14--4, 5details
#15--5details
#16--5details
#17--5details
#18--5details
#19--5details
#20--5details
#21--5details
#22ACCEPTED0.00 s1, 2, 3, 4, 5details
#23ACCEPTED0.00 s1, 2, 3, 4, 5details
#24ACCEPTED0.43 s5details
#25ACCEPTED0.43 s5details
#26ACCEPTED0.66 s5details
#27ACCEPTED0.46 s5details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
   53 |     for (int i = 0; i < query_count; i++) {
      |                     ~~^~~~~~~~~~~~~

Code

#include <iostream>
#include <unordered_map>
#include <string.h> // memset
#include <vector>



typedef unsigned char uchar;

// row/column
class Row {
public:
    std::vector<uchar> connected_columns;

    Row() {}

    void connect_with(uchar other_idx) {
        connected_columns.push_back(other_idx);
    }
};



unsigned short height, width;
unsigned int query_count;
int main() {
    Row rows[250];
    Row columns[250];

    std::cin >> height >> width >> query_count;

    for (int i = 0; i < width; i++) {
        columns[i] = Row();
    }

    for (int i = 0; i < height; i++) {
        Row row = Row();
        // <------
        
        char buf[251];
        std::cin >> buf;

        for (int j = 0; j < width; j++) {
            if (buf[j] == '.') {
                row.connect_with(j);
                columns[j].connect_with(i);
                //std::cout << "Connect row idx " << i << " to column idx " << j << std::endl;
            }
        }
        rows[i] = row;
    }

    for (int i = 0; i < query_count; i++) {
        bool available_rows[250], available_cols[250];
        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;
        }

        memset(&available_rows, 0, 250);
        memset(&available_cols, 0, 250);

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

        available_cols[start_x] = true;
        available_rows[start_y] = true;
        
        memset(&just_added_rows, 0, 250);
        memset(&just_added_cols, 0, 250);

        just_added_cols[start_x] = true;
        just_added_rows[start_y] = true;
        
        for (int cost = 2;; cost++) {
            bool rows_to_add[250];
            bool cols_to_add[250];
            memset(&rows_to_add, 0, 250);
            memset(&cols_to_add, 0, 250);
        
            // 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 < 250; row_idx++) {
                if (!just_added_rows[row_idx]) { continue; }
                
                //std::cout << "Row " << (int) row_idx << std::endl;
                just_added_rows[row_idx] = false;

                Row row = rows[row_idx];
                for (uchar col_idx : row.connected_columns) {
                    //std::cout << "Add col " << (int) col_idx << std::endl;
                    cols_to_add[col_idx] = true;
                    no_solution = false;
                }
            }

            for (uchar col_idx = 0; col_idx < 250; col_idx++) {
                if (!just_added_cols[col_idx]) { continue; }

                //std::cout << "Col " << (int) col_idx << std::endl;
                just_added_cols[col_idx] = false;

                Row col = columns[col_idx];
                for (uchar row_idx : col.connected_columns) {
                    //std::cout << "Add row " << (int) row_idx << std::endl;
                    rows_to_add[row_idx] = true;
                    no_solution = false;
                }
            }

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


            if (rows_to_add[end_y] || cols_to_add[end_x]) { std::cout << cost << '\n'; goto complete; }
            for (uchar idx = 0; idx < 250; idx++) {
                if (rows_to_add[idx]) {
                    rows_to_add[idx] = false;

                    if (!available_rows[idx]) {
                        available_rows[idx] = true;
                        just_added_rows[idx] = true;
                    }
                    
                    //if (idx == end_y) { std::cout << cost << '\n'; goto complete; }
                }

                if (cols_to_add[idx]) {
                    cols_to_add[idx] = false;

                    if (!available_cols[idx]) {
                        available_rows[idx] = true;
                        just_added_cols[idx] = true;
                    }

                    //if (idx == end_x) { std::cout << cost << '\n'; goto complete; }
                }
            }
        }
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:

input
10 10 1
.****.****
**.**..***
**********
*******..*
...

correct output
7

user output
-1

Feedback: Incorrect character on line 1 col 1: expected "7", got "-1"

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:

input
80 80 200000
*******.*****.*..*..****...***...

correct output
2
3
1
2
2
...

user output
(empty)

Test 15

Group: 5

Verdict:

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

correct output
3
2
2
2
2
...

user output
(empty)

Test 16

Group: 5

Verdict:

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

correct output
2
2
2
2
2
...

user output
(empty)

Test 17

Group: 5

Verdict:

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

correct output
3
3
2
2
2
...

user output
(empty)

Test 18

Group: 5

Verdict:

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

correct output
3
3
3
3
3
...

user output
(empty)

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