# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1089502 |
2024-09-16T15:32:53 Z |
Gervid |
Zoo (COCI19_zoo) |
C++17 |
|
79 ms |
2908 KB |
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
using namespace std;
struct node
{
int x, y;
int layer;
const bool operator< (const node other) const
{
return layer > other.layer;
}
};
int r, c;
bool outofbounds(node n)
{
return !(0 <= n.x && n.x < r && 0 <= n.y && n.y < c);
}
int main()
{
iostream::sync_with_stdio(0);
cin.tie(0);
int i, j, deepest_layer = 0;
cin >> r >> c;
vector<string> g(r);
for (i = 0; i < r; i++)
{
cin >> g[i];
}
priority_queue<node> q;
q.push({ 0, 0, 0 });
vector<vector<bool>> been(r, vector<bool>(c, 0));
vector<pair<int, int>> directions = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
while (!q.empty())
{
node current = q.top();
q.pop();
for (pair<int, int>& d : directions)
{
node neighbour;
neighbour.x = current.x + d.first;
neighbour.y = current.y + d.second;
if (!outofbounds(neighbour) && !been[neighbour.x][neighbour.y] && g[neighbour.x][neighbour.y] != '*')
{
neighbour.layer = current.layer + (g[neighbour.x][neighbour.y] != g[current.x][current.y]);
deepest_layer = max(deepest_layer, neighbour.layer);
q.push(neighbour);
been[neighbour.x][neighbour.y] = true;
}
}
}
cout << deepest_layer + 1;
}
Compilation message
zoo.cpp: In function 'int main()':
zoo.cpp:36:9: warning: unused variable 'j' [-Wunused-variable]
36 | int i, j, deepest_layer = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
9 ms |
2648 KB |
Output is correct |
17 |
Correct |
9 ms |
2652 KB |
Output is correct |
18 |
Correct |
13 ms |
2908 KB |
Output is correct |
19 |
Correct |
12 ms |
2768 KB |
Output is correct |
20 |
Correct |
13 ms |
2732 KB |
Output is correct |
21 |
Correct |
57 ms |
2544 KB |
Output is correct |
22 |
Correct |
58 ms |
2396 KB |
Output is correct |
23 |
Correct |
56 ms |
2392 KB |
Output is correct |
24 |
Correct |
62 ms |
2648 KB |
Output is correct |
25 |
Correct |
58 ms |
2904 KB |
Output is correct |
26 |
Correct |
69 ms |
2904 KB |
Output is correct |
27 |
Correct |
67 ms |
2396 KB |
Output is correct |
28 |
Correct |
60 ms |
2396 KB |
Output is correct |
29 |
Correct |
79 ms |
2648 KB |
Output is correct |
30 |
Correct |
59 ms |
2648 KB |
Output is correct |