#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++)
{
cin >> 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: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++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
3164 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
648 KB |
Output is correct |
4 |
Correct |
16 ms |
3216 KB |
Output is correct |
5 |
Correct |
3 ms |
1884 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
1628 KB |
Output is correct |
11 |
Correct |
4 ms |
1604 KB |
Output is correct |
12 |
Correct |
10 ms |
2056 KB |
Output is correct |
13 |
Correct |
3 ms |
1884 KB |
Output is correct |
14 |
Correct |
3 ms |
1884 KB |
Output is correct |
15 |
Correct |
20 ms |
3356 KB |
Output is correct |
16 |
Correct |
27 ms |
3160 KB |
Output is correct |
17 |
Correct |
13 ms |
3160 KB |
Output is correct |
18 |
Correct |
23 ms |
3228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15452 KB |
Output is correct |
2 |
Correct |
80 ms |
9896 KB |
Output is correct |
3 |
Correct |
237 ms |
61780 KB |
Output is correct |
4 |
Correct |
86 ms |
18952 KB |
Output is correct |
5 |
Correct |
131 ms |
38196 KB |
Output is correct |
6 |
Correct |
1964 ms |
78400 KB |
Output is correct |
7 |
Correct |
6 ms |
16472 KB |
Output is correct |
8 |
Correct |
6 ms |
15452 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
15964 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
72 ms |
10028 KB |
Output is correct |
14 |
Correct |
47 ms |
6744 KB |
Output is correct |
15 |
Correct |
12 ms |
7464 KB |
Output is correct |
16 |
Correct |
38 ms |
3932 KB |
Output is correct |
17 |
Correct |
195 ms |
20356 KB |
Output is correct |
18 |
Correct |
52 ms |
20060 KB |
Output is correct |
19 |
Correct |
87 ms |
18768 KB |
Output is correct |
20 |
Correct |
68 ms |
17456 KB |
Output is correct |
21 |
Correct |
150 ms |
39252 KB |
Output is correct |
22 |
Correct |
130 ms |
38024 KB |
Output is correct |
23 |
Correct |
382 ms |
31828 KB |
Output is correct |
24 |
Correct |
111 ms |
37432 KB |
Output is correct |
25 |
Correct |
201 ms |
59960 KB |
Output is correct |
26 |
Correct |
957 ms |
47696 KB |
Output is correct |
27 |
Correct |
1613 ms |
62100 KB |
Output is correct |
28 |
Execution timed out |
2023 ms |
76476 KB |
Time limit exceeded |
29 |
Execution timed out |
2049 ms |
68128 KB |
Time limit exceeded |
30 |
Correct |
1986 ms |
66812 KB |
Output is correct |
31 |
Correct |
1289 ms |
41944 KB |
Output is correct |
32 |
Correct |
1225 ms |
60872 KB |
Output is correct |