| Task: | Hypyt |
| Sender: | Lelleri |
| Submission time: | 2025-11-05 11:27:33 +0200 |
| Language: | C++ (C++11) |
| 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.01 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.91 s | 2, 5 | details |
| #7 | ACCEPTED | 0.67 s | 2, 5 | details |
| #8 | ACCEPTED | 0.35 s | 2, 5 | details |
| #9 | ACCEPTED | 0.41 s | 3, 4, 5 | details |
| #10 | ACCEPTED | 0.41 s | 3, 4, 5 | details |
| #11 | ACCEPTED | 0.41 s | 3, 4, 5 | details |
| #12 | ACCEPTED | 0.45 s | 4, 5 | details |
| #13 | ACCEPTED | 0.44 s | 4, 5 | details |
| #14 | ACCEPTED | 0.43 s | 4, 5 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #17 | ACCEPTED | 0.84 s | 5 | details |
| #18 | ACCEPTED | 0.67 s | 5 | details |
| #19 | ACCEPTED | 0.54 s | 5 | details |
| #20 | ACCEPTED | 0.55 s | 5 | details |
| #21 | ACCEPTED | 0.44 s | 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.41 s | 5 | details |
| #25 | ACCEPTED | 0.41 s | 5 | details |
| #26 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #27 | ACCEPTED | 0.36 s | 5 | details |
Compiler report
input/code.cpp: In function 'std::unordered_map<int, int> bfs(int, int, std::vector<std::vector<Node> >&, std::vector<std::vector<Node> >&, Node&)':
input/code.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int c=0; c<rows[current.pos.second].size(); c++){
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int c=0; c<columns[current.pos.first].size(); c++){
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Code
#include <bits/stdc++.h>
using namespace std;
struct Node {
char type; // n = cell, r = row, c = column
pair<int, int> pos;
};
int id(Node& node, int n, int m){
if(node.type == 'r'){
return n*m+node.pos.second;
}
else if(node.type == 'c'){
return n*m+n+node.pos.first;
}
else{
return m*node.pos.second+node.pos.first;
}
}
unordered_map<int, int> bfs(int n, int m, vector<vector<Node>>& rows, vector<vector<Node>>& columns, Node& start){
vector<bool> visited (n*m+n+m, false);
queue<pair<Node, int>> q; // {current, move_count}
q.push({start, 0});
visited[id(start, n, m)] = true;
unordered_map<int, int> table;
while (q.size() > 0){
Node current = q.front().first;
int move_count = q.front().second;
q.pop();
if(current.type == 'r'){
table[id(current, n, m)] = move_count+1;
for(int c=0; c<rows[current.pos.second].size(); c++){
Node v = rows[current.pos.second][c];
if(!visited[id(v, n, m)]){
q.push({v, move_count+1});
visited[id(v, n, m)] = true;
}
}
}
if(current.type == 'c'){
table[id(current, n, m)] = move_count+1;
for(int c=0; c<columns[current.pos.first].size(); c++){
Node v = columns[current.pos.first][c];
if(!visited[id(v, n, m)]){
q.push({v, move_count+1});
visited[id(v, n, m)] = true;
}
}
}
if(current.type == 'n'){
Node row = {'r', {-1, current.pos.second}};
if(!visited[id(row, n, m)]){
q.push({row, move_count});
visited[id(row, n, m)] = true;
}
Node column = {'c', {current.pos.first, -1}};
if(!visited[id(column, n, m)]){
q.push({column, move_count});
visited[id(column, n, m)] = true;
}
}
}
return table;
}
int main() {
ios_base::sync_with_stdio (false);
int n, m, q;
cin >> n >> m >> q;
vector<vector<char>> grid(n, vector<char>(m, 0));
vector<vector<Node>> rows;
vector<vector<Node>> columns;
for(int i=0; i < n; i++){
for(int j=0; j < m; j++){
cin >> grid[i][j];
}
}
for(int i=0; i < n; i++){
vector<Node> row = {};
for(int j=0; j < m; j++){
if(grid[i][j] == '*') continue;
Node node = {'n', {j, i}};
row.push_back(node);
}
rows.push_back(row);
}
for(int j=0; j < m; j++){
vector<Node> column = {};
for(int i=0; i < n; i++){
if(grid[i][j] == '*') continue;
Node node = {'n', {j, i}};
column.push_back(node);
}
columns.push_back(column);
}
unordered_map<int, unordered_map<int, int>> table;
for(int i=0; i < n; i++){
Node start_row = {'r', {-1, i}};
table[id(start_row, n, m)] = bfs(n, m, rows, columns, start_row);
}
for(int j=0; j < m; j++){
Node start_col = {'c', {j, -1}};
table[id(start_col, n, m)] = bfs(n, m, rows, columns, start_col);
}
for(int i=0; i < q; i++){
int x1, y1, x2, y2;
cin >> y1 >> x1 >> y2 >> x2;
if(y1==y2 && x1==x2){
cout << 0 << "\n";
continue;
}
int start_row_id = n*m+(y1-1);
int end_row_id = n*m+(y2-1);
int start_col_id = n*m+n+(x1-1);
int end_col_id = n*m+n+(x2-1);
if(table[start_row_id][end_row_id] == 0 || table[start_row_id][end_col_id] == 0 || table[start_col_id][end_row_id] == 0 || table[start_col_id][end_col_id] == 0){
cout << -1 << "\n";
continue;
}
int row = min(table[start_row_id][end_row_id], table[start_row_id][end_col_id]);
int col = min(table[start_col_id][end_row_id], table[start_col_id][end_col_id]);
cout << min(row, col) << "\n";
}
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: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *....*..*..*..**..*.........**... |
| correct output |
|---|
| 3 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 16
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..*....*..*......*.**.*.*..***... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
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: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ................................. |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 27
Group: 5
Verdict: ACCEPTED
| input |
|---|
| 250 250 200000 ******************************... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| 0 0 0 0 0 ... |
