| Task: | Hypyt |
| Sender: | Lelleri |
| Submission time: | 2025-11-06 21:44:09 +0200 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | ACCEPTED | 20 |
| #3 | ACCEPTED | 15 |
| #4 | ACCEPTED | 15 |
| #5 | ACCEPTED | 40 |
| 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.01 s | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #6 | ACCEPTED | 0.60 s | 2, 5 | details |
| #7 | ACCEPTED | 0.43 s | 2, 5 | details |
| #8 | ACCEPTED | 0.20 s | 2, 5 | details |
| #9 | ACCEPTED | 0.04 s | 3, 4, 5 | details |
| #10 | ACCEPTED | 0.04 s | 3, 4, 5 | details |
| #11 | ACCEPTED | 0.04 s | 3, 4, 5 | details |
| #12 | ACCEPTED | 0.06 s | 4, 5 | details |
| #13 | ACCEPTED | 0.05 s | 4, 5 | details |
| #14 | ACCEPTED | 0.04 s | 4, 5 | details |
| #15 | ACCEPTED | 0.65 s | 5 | details |
| #16 | ACCEPTED | 0.47 s | 5 | details |
| #17 | ACCEPTED | 0.24 s | 5 | details |
| #18 | ACCEPTED | 0.13 s | 5 | details |
| #19 | ACCEPTED | 0.07 s | 5 | details |
| #20 | ACCEPTED | 0.06 s | 5 | details |
| #21 | ACCEPTED | 0.06 s | 5 | details |
| #22 | ACCEPTED | 0.01 s | 1, 2, 3, 4, 5 | details |
| #23 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #24 | ACCEPTED | 0.04 s | 5 | details |
| #25 | ACCEPTED | 0.04 s | 5 | details |
| #26 | ACCEPTED | 0.79 s | 5 | details |
| #27 | ACCEPTED | 0.04 s | 5 | details |
Compiler report
input/code.cpp: In function 'std::vector<int> bfs(int, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, int, std::vector<int>&, std::vector<int>&)':
input/code.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int c=0; c<rows[row_index].size(); c++){
| ~^~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int c=0; c<columns[column_index].size(); c++){
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%d %d %d", &n,...Code
#include <bits/stdc++.h>
using namespace std;
void fast_scan(int &number){
number = 0;
char c = getchar();
while(c < '0' || '9' < c){
c = getchar();
}
for (; (c>='0' && c<='9'); c=getchar()){
number = number * 10 + c - 48;
}
}
vector<unsigned char> visited (63000, 0);
vector<int> bfs(int n, int m, vector<vector<int>>& rows, vector<vector<int>>& columns, int start, vector<int>& row_nodes, vector<int>& column_nodes){
queue<pair<int, int>> q; // {current, move_count}
q.push({start, 0});
visited[start] = 1;
vector<int> table(n+m, -1);
while (q.size() > 0){
int current = q.front().first;
int move_count = q.front().second;
q.pop();
if(current < n*m){ // node
int row_index = current/m;
if(!visited[row_nodes[row_index]]){
q.push({row_nodes[row_index], move_count});
visited[row_nodes[row_index]] = 1;
}
int column_index = current%m;
if(!visited[column_nodes[column_index]]){
q.push({column_nodes[column_index], move_count});
visited[column_nodes[column_index]] = 1;
}
}
else if(current < n*m+n){ // row
int row_index = (current-n*m);
table[row_index] = move_count+1;
for(int c=0; c<rows[row_index].size(); c++){
if(!visited[rows[row_index][c]]){
q.push({rows[row_index][c], move_count+1});
visited[rows[row_index][c]] = 1;
}
}
}
else{ // column
int column_index = (current-n*m-n);
table[n+column_index] = move_count+1;
for(int c=0; c<columns[column_index].size(); c++){
if(!visited[columns[column_index][c]]){
q.push({columns[column_index][c], move_count+1});
visited[columns[column_index][c]] = 1;
}
}
}
}
fill(visited.begin(), visited.end(), 0);
return table;
}
int main() {
char buffer[1<<20];
setvbuf(stdout, buffer, _IOFBF, sizeof(buffer));
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
vector<vector<char>> grid(n, vector<char>(m, 0));
vector<vector<int>> rows;
vector<vector<int>> columns;
vector<int> row_nodes;
vector<int> column_nodes;
for(int i=0; i < n; i++){
vector<int> row = {};
char line[m+1];
scanf(" %[^\n]", line);
for(int j=0; j < m; j++){
grid[i][j] = line[j];
if(grid[i][j] == '*') continue;
row.push_back(i*m+j);
}
rows.push_back(row);
row_nodes.push_back(n*m+i);
}
for(int j=0; j < m; j++){
vector<int> column = {};
for(int i=0; i < n; i++){
if(grid[i][j] == '*') continue;
column.push_back(i*m+j);
}
columns.push_back(column);
column_nodes.push_back(n*m+n+j);
}
vector<vector<int>> table(n+m, vector<int>(n+m, -1));
for(int i=0; i < n; i++){
table[i] = bfs(n, m, rows, columns, n*m+i, row_nodes, column_nodes);
}
for(int j=0; j < m; j++){
table[n+j] = bfs(n, m, rows, columns, n*m+n+j, row_nodes, column_nodes);
}
for(int i=0; i < q; i++){
int x1, y1, x2, y2;
fast_scan(y1);
fast_scan(x1);
fast_scan(y2);
fast_scan(x2);
if(y1==y2 && x1==x2){
printf("%d\n", 0);
continue;
}
int p1 = table[y1-1][y2-1];
int p2 = table[y1-1][n+(x2-1)];
int p3 = table[n+(x1-1)][y2-1];
int p4 = table[n+(x1-1)][n+(x2-1)];
printf("%d\n", min(min(p1, p2), min(p3, p4)));
}
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: ACCEPTED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 498 498 498 498 498 ... |
| user output |
|---|
| 498 498 498 498 498 ... |
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 ... |
