#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});
assert(1 == 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++;
}
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:56: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]
56 | while(i < pq_vec.size())
| ~~^~~~~~~~~~~~~~~
tracks.cpp:59: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]
59 | while (j < pq_vec[i].size())
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
16724 KB |
Execution killed with signal 6 |
2 |
Runtime error |
1 ms |
428 KB |
Execution killed with signal 6 |
3 |
Runtime error |
1 ms |
552 KB |
Execution killed with signal 6 |
4 |
Runtime error |
9 ms |
10872 KB |
Execution killed with signal 6 |
5 |
Runtime error |
5 ms |
6072 KB |
Execution killed with signal 6 |
6 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
7 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
8 |
Runtime error |
1 ms |
680 KB |
Execution killed with signal 6 |
9 |
Runtime error |
2 ms |
1108 KB |
Execution killed with signal 6 |
10 |
Runtime error |
5 ms |
4884 KB |
Execution killed with signal 6 |
11 |
Runtime error |
3 ms |
3124 KB |
Execution killed with signal 6 |
12 |
Runtime error |
6 ms |
6300 KB |
Execution killed with signal 6 |
13 |
Runtime error |
5 ms |
6100 KB |
Execution killed with signal 6 |
14 |
Runtime error |
7 ms |
6172 KB |
Execution killed with signal 6 |
15 |
Runtime error |
19 ms |
17464 KB |
Execution killed with signal 6 |
16 |
Runtime error |
14 ms |
16852 KB |
Execution killed with signal 6 |
17 |
Runtime error |
17 ms |
16624 KB |
Execution killed with signal 6 |
18 |
Runtime error |
9 ms |
10836 KB |
Execution killed with signal 6 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
4052 KB |
Execution killed with signal 6 |
2 |
Runtime error |
92 ms |
104816 KB |
Execution killed with signal 6 |
3 |
Runtime error |
916 ms |
1048576 KB |
Execution killed with signal 6 |
4 |
Runtime error |
211 ms |
253036 KB |
Execution killed with signal 6 |
5 |
Runtime error |
483 ms |
595236 KB |
Execution killed with signal 6 |
6 |
Runtime error |
875 ms |
1048576 KB |
Execution killed with signal 6 |
7 |
Runtime error |
3 ms |
3668 KB |
Execution killed with signal 6 |
8 |
Runtime error |
4 ms |
4052 KB |
Execution killed with signal 6 |
9 |
Runtime error |
6 ms |
4436 KB |
Execution killed with signal 6 |
10 |
Runtime error |
4 ms |
2644 KB |
Execution killed with signal 6 |
11 |
Runtime error |
6 ms |
3928 KB |
Execution killed with signal 6 |
12 |
Runtime error |
2 ms |
1952 KB |
Execution killed with signal 6 |
13 |
Runtime error |
125 ms |
104536 KB |
Execution killed with signal 6 |
14 |
Runtime error |
59 ms |
61244 KB |
Execution killed with signal 6 |
15 |
Runtime error |
65 ms |
67720 KB |
Execution killed with signal 6 |
16 |
Runtime error |
39 ms |
42700 KB |
Execution killed with signal 6 |
17 |
Runtime error |
236 ms |
273404 KB |
Execution killed with signal 6 |
18 |
Runtime error |
230 ms |
269932 KB |
Execution killed with signal 6 |
19 |
Runtime error |
217 ms |
253068 KB |
Execution killed with signal 6 |
20 |
Runtime error |
205 ms |
232512 KB |
Execution killed with signal 6 |
21 |
Runtime error |
478 ms |
615776 KB |
Execution killed with signal 6 |
22 |
Runtime error |
496 ms |
595420 KB |
Execution killed with signal 6 |
23 |
Runtime error |
425 ms |
511624 KB |
Execution killed with signal 6 |
24 |
Runtime error |
500 ms |
602164 KB |
Execution killed with signal 6 |
25 |
Runtime error |
807 ms |
1048576 KB |
Execution killed with signal 6 |
26 |
Runtime error |
644 ms |
810452 KB |
Execution killed with signal 6 |
27 |
Runtime error |
859 ms |
1048576 KB |
Execution killed with signal 6 |
28 |
Runtime error |
853 ms |
1048576 KB |
Execution killed with signal 6 |
29 |
Runtime error |
814 ms |
1048576 KB |
Execution killed with signal 6 |
30 |
Runtime error |
861 ms |
1048576 KB |
Execution killed with signal 6 |
31 |
Runtime error |
575 ms |
676492 KB |
Execution killed with signal 6 |
32 |
Runtime error |
835 ms |
1048576 KB |
Execution killed with signal 6 |