This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4009;
typedef long long ll;
int N , M;
string s[maxn];
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++ )s[0] += '&';
for(int i = 0 ; i <= M+1 ; i++ )s[N+1] += '&';
pr();
for(int i = 1 ; i <= N ;i++)
{
cin >> s[i];
s[i] = '&'+s[i]+'&';
}
priority_queue <pair<int,int>> q;
q.push({-1,1*maxn+1});
int i , j;
while(!q.empty())
{
c = -q.top().first;
i = q.top().second/maxn;
j = q.top().second%maxn;
q.pop();
if(vis[i][j] == 1){continue;}
vis[i][j] = 1;
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] == '&' || s[a][b] == '.' || vis[a][b] == 1)continue;
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 (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:49: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]
49 | for(int k = 0 ; k < R.size() ; k++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |