#include <iostream>
#include <fstream>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <numeric>
#include <string>
#include <bitset>
#include <set>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll dr[4] = {0, 1, 0, -1};
ll dc[4] = {1, 0, -1, 0};
int main()
{
cin.tie(0) -> sync_with_stdio(0);
ll h, w;
cin >> h >> w;
string grid[h];
for (ll i = 0; i < h; i++) {
cin >> grid[i];
}
deque<pair<pair<ll, ll>, ll>> q;
q.push_front({{0, 0}, 1});
ll dist[h][w];
memset(dist, -1, sizeof(dist));
while (!q.empty()) {
pair<pair<ll, ll>, ll> cur = q.front();
q.pop_front();
if (dist[cur.first.first][cur.first.second] != -1) {
continue;
}
dist[cur.first.first][cur.first.second] = cur.second;
for (ll i = 0; i < 4; i++) {
ll nr = cur.first.first+dr[i];
ll nc = cur.first.second+dc[i];
if (nr>=0 && nr<h && nc>=0 && nc<w && grid[nr][nc]!='.') {
if (grid[cur.first.first][cur.first.second] != grid[nr][nc]) {
q.push_back({{nr, nc}, cur.second+1});
} else {
q.push_front({{nr, nc}, cur.second});
}
}
}
}
ll ans = 0;
for (ll i=0; i<h; i++) {
for (ll j=0; j<w; j++) {
ans=max(ans,dist[i][j]);
}
}
cout<<ans<<"\n";
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:36:6: error: 'memset' was not declared in this scope
36 | memset(dist, -1, sizeof(dist));
| ^~~~~~
tracks.cpp:11:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
10 | #include <set>
+++ |+#include <cstring>
11 | using namespace std;