#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
typedef long long ll;
int H, W;
vector<string> grid;
vector<vector<ll>> visited; // bitset ?
//priority_queue<vector<ll>> q;
vector<vector<pair<ll, ll>>> pq_vec;
void dfs(int hat, int wat, ll num)
{
if (visited[hat][wat]>0) return;
if (grid[hat][wat] == '.') return;
visited[hat][wat] = num;
char ch = grid[hat][wat];
if (hat + 1 < H) {
if (grid[hat + 1][wat] == ch) pq_vec[num].push_back({hat + 1, wat});
else pq_vec[num + 1].push_back({hat + 1, wat});
}
if (wat + 1 < W) {
if (grid[hat][wat + 1] == ch) pq_vec[num].push_back({hat, wat + 1});
else pq_vec[num + 1].push_back({hat, wat + 1});
}
if (hat - 1 >= 0) {
if (grid[hat - 1][wat] == ch) pq_vec[num].push_back({hat - 1, wat});
else pq_vec[num + 1].push_back({hat - 1, wat});
}
if (wat - 1 >= 0) {
if (grid[hat][wat - 1] == ch) pq_vec[num].push_back({hat, wat - 1});
else pq_vec[num + 1].push_back({hat, wat - 1});
}
}
int32_t main()
{
cin>>H>>W;
grid.assign(H, "");
rep(i,0,H){
cin>>grid[i];
}
visited.assign(H, vector<ll>(W, -1));
//q.push({-1,0,0});
pq_vec.assign(H*W + 1, {});
pq_vec[1].push_back({0,0});
ll i = 1;
while(i < pq_vec.size())
{
ll j = 0;
while (j < pq_vec[i].size())
{
pair<ll,ll> x = pq_vec[i][j];
dfs(x.first, x.second, i);
j++;
}
i++;
}
assert(1 == 0);
ll ans = 1;
rep(i,0,H){
rep(j,0,W){
ans = max(ans, visited[i][j]);
}
}
cout << ans;
}
Compilation message
tracks.cpp: In function 'int32_t main()':
tracks.cpp:54:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | while(i < pq_vec.size())
| ~~^~~~~~~~~~~~~~~
tracks.cpp:57:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | while (j < pq_vec[i].size())
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
51 ms |
47208 KB |
Execution killed with signal 6 |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 6 |
4 |
Runtime error |
36 ms |
33728 KB |
Execution killed with signal 6 |
5 |
Runtime error |
9 ms |
9108 KB |
Execution killed with signal 6 |
6 |
Runtime error |
1 ms |
424 KB |
Execution killed with signal 6 |
7 |
Runtime error |
1 ms |
852 KB |
Execution killed with signal 6 |
8 |
Runtime error |
2 ms |
1492 KB |
Execution killed with signal 6 |
9 |
Runtime error |
2 ms |
1332 KB |
Execution killed with signal 6 |
10 |
Runtime error |
9 ms |
8836 KB |
Execution killed with signal 6 |
11 |
Runtime error |
10 ms |
11628 KB |
Execution killed with signal 6 |
12 |
Runtime error |
18 ms |
16976 KB |
Execution killed with signal 6 |
13 |
Runtime error |
9 ms |
9220 KB |
Execution killed with signal 6 |
14 |
Runtime error |
9 ms |
9140 KB |
Execution killed with signal 6 |
15 |
Runtime error |
43 ms |
41204 KB |
Execution killed with signal 6 |
16 |
Runtime error |
51 ms |
47240 KB |
Execution killed with signal 6 |
17 |
Runtime error |
33 ms |
30892 KB |
Execution killed with signal 6 |
18 |
Runtime error |
34 ms |
33692 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
6228 KB |
Execution killed with signal 6 |
2 |
Runtime error |
218 ms |
192036 KB |
Execution killed with signal 6 |
3 |
Runtime error |
1496 ms |
1048576 KB |
Execution killed with signal 6 |
4 |
Runtime error |
357 ms |
333296 KB |
Execution killed with signal 6 |
5 |
Runtime error |
1200 ms |
1048576 KB |
Execution killed with signal 6 |
6 |
Runtime error |
1356 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Runtime error |
7 ms |
5620 KB |
Execution killed with signal 6 |
8 |
Runtime error |
6 ms |
6228 KB |
Execution killed with signal 6 |
9 |
Runtime error |
9 ms |
8804 KB |
Execution killed with signal 6 |
10 |
Runtime error |
3 ms |
3852 KB |
Execution killed with signal 6 |
11 |
Runtime error |
5 ms |
5076 KB |
Execution killed with signal 6 |
12 |
Runtime error |
4 ms |
3796 KB |
Execution killed with signal 6 |
13 |
Runtime error |
217 ms |
191412 KB |
Execution killed with signal 6 |
14 |
Runtime error |
128 ms |
113368 KB |
Execution killed with signal 6 |
15 |
Runtime error |
116 ms |
118332 KB |
Execution killed with signal 6 |
16 |
Runtime error |
100 ms |
91560 KB |
Execution killed with signal 6 |
17 |
Runtime error |
571 ms |
491924 KB |
Execution killed with signal 6 |
18 |
Runtime error |
481 ms |
464744 KB |
Execution killed with signal 6 |
19 |
Runtime error |
346 ms |
331464 KB |
Execution killed with signal 6 |
20 |
Runtime error |
366 ms |
394500 KB |
Execution killed with signal 6 |
21 |
Runtime error |
947 ms |
1030020 KB |
Execution killed with signal 6 |
22 |
Runtime error |
1132 ms |
1048576 KB |
Execution killed with signal 6 |
23 |
Runtime error |
1067 ms |
916988 KB |
Execution killed with signal 6 |
24 |
Runtime error |
985 ms |
1048576 KB |
Execution killed with signal 6 |
25 |
Runtime error |
1658 ms |
1048576 KB |
Execution killed with signal 6 |
26 |
Runtime error |
1213 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Runtime error |
914 ms |
1048576 KB |
Execution killed with signal 9 |
28 |
Runtime error |
1461 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Runtime error |
1443 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Runtime error |
1517 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Execution timed out |
2051 ms |
1048576 KB |
Time limit exceeded |
32 |
Runtime error |
1000 ms |
1048576 KB |
Execution killed with signal 9 |