#include <bits/stdc++.h>
using namespace std;
const int maxn = 4009;
typedef long long ll;
int N , M;
string s[maxn];
string SA;
int a , b , c;
vector <pair<int,int>> R;
bool vis[maxn][maxn];
int MAXI = 0;
void pr()
{
R.push_back({-1,0});
R.push_back({1,0});
R.push_back({0,1});
R.push_back({0,-1});
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for(int i = 0 ; i <= M+1 ; i++)SA.push_back( '.');
s[0] = SA;
s[N+1] = SA;
pr();
for(int i = 1 ; i <= N ;i++)
{
gets(SA);
s[i] = '.';
s[i] += SA;
s[i].push_back('.');
}
priority_queue <pair<int,int>> q;
pair<int,int> DS;
q.push({-1,1*maxn+1});
int i , j;
vis[1][1] = 1;
while(!q.empty())
{
DS = q.top();
c = -DS.first;
i = DS.second/maxn;
j = DS.second%maxn;
q.pop();
MAXI = max(MAXI , c);
for(int k = 0 ; k < R.size() ; k++)
{
a = i+R[k].first;
b = j+R[k].second;
if(s[a][b] == '.' || vis[a][b])continue;
vis[a][b] = 1;
if(s[a][b] == s[i][j]){ q.push({-c,a*maxn+b});}
else {q.push({-(c+1),a*maxn+b});}
}
}
cout << MAXI << '\n';
return 0;
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:34:9: error: 'gets' was not declared in this scope; did you mean 'fgets'?
34 | gets(SA);
| ^~~~
| fgets
tracks.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int k = 0 ; k < R.size() ; k++)
| ~~^~~~~~~~~~