#define nametask "tracks"
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define SZ(a) (int) a.size()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, b, a) for (int i = b; i >= a; i--)
using namespace std;
typedef long long ll;
typedef pair <int, int> pi;
const pi dir[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
const int N = 4005;
int n, m;
char a[N][N];
int d[N][N];
bool ok(int i, int j){
return (i >= 1 && i <= n && j >= 1 && j <= m);
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
if (fopen(nametask".inp", "r")){
freopen(nametask".inp", "r", stdin);
freopen(nametask".out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++) d[i][j] = 0;
}
int ans = 1;
deque <pi> dq;
d[1][1] = 1;
dq.push_back(mp(1, 1));
while (!dq.empty()){
pi top = dq.front();
cout << top.fi << ' ' << top.se << ' ' << d[top.fi][top.se] << '\n';
ans = max(ans, d[top.fi][top.se]);
dq.pop_front();
for (int i = 0; i < 4; i++){
int u = top.fi + dir[i].fi, v = top.se + dir[i].se;
if (ok(u, v) && (a[u][v] != '.') && (d[u][v] == 0)){
if (a[u][v] == a[top.fi][top.se]){
d[u][v] = d[top.fi][top.se];
dq.push_front(mp(u, v));
}
else {
d[u][v] = d[top.fi][top.se] + 1;
dq.push_back(mp(u, v));
}
}
}
}
cout << ans;
return 0;
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen(nametask".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen(nametask".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
15444 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Incorrect |
29 ms |
14496 KB |
Output isn't correct |
5 |
Incorrect |
8 ms |
11096 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
4568 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
7004 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
7028 KB |
Output isn't correct |
12 |
Incorrect |
18 ms |
11612 KB |
Output isn't correct |
13 |
Incorrect |
6 ms |
10844 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
10840 KB |
Output isn't correct |
15 |
Incorrect |
37 ms |
14932 KB |
Output isn't correct |
16 |
Incorrect |
47 ms |
15280 KB |
Output isn't correct |
17 |
Incorrect |
25 ms |
14160 KB |
Output isn't correct |
18 |
Incorrect |
29 ms |
14432 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
78680 KB |
Output isn't correct |
2 |
Incorrect |
138 ms |
35676 KB |
Output isn't correct |
3 |
Incorrect |
906 ms |
149976 KB |
Output isn't correct |
4 |
Incorrect |
159 ms |
50984 KB |
Output isn't correct |
5 |
Incorrect |
912 ms |
143680 KB |
Output isn't correct |
6 |
Execution timed out |
2021 ms |
220248 KB |
Time limit exceeded |
7 |
Incorrect |
11 ms |
78940 KB |
Output isn't correct |
8 |
Incorrect |
11 ms |
78680 KB |
Output isn't correct |
9 |
Incorrect |
6 ms |
5068 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
2652 KB |
Output isn't correct |
11 |
Incorrect |
10 ms |
78360 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
6748 KB |
Output isn't correct |
13 |
Incorrect |
150 ms |
35732 KB |
Output isn't correct |
14 |
Incorrect |
81 ms |
25936 KB |
Output isn't correct |
15 |
Incorrect |
62 ms |
27732 KB |
Output isn't correct |
16 |
Incorrect |
73 ms |
15444 KB |
Output isn't correct |
17 |
Incorrect |
363 ms |
66832 KB |
Output isn't correct |
18 |
Incorrect |
239 ms |
63312 KB |
Output isn't correct |
19 |
Incorrect |
153 ms |
51284 KB |
Output isn't correct |
20 |
Incorrect |
205 ms |
52960 KB |
Output isn't correct |
21 |
Incorrect |
564 ms |
105932 KB |
Output isn't correct |
22 |
Incorrect |
914 ms |
143508 KB |
Output isn't correct |
23 |
Incorrect |
745 ms |
101024 KB |
Output isn't correct |
24 |
Incorrect |
638 ms |
118456 KB |
Output isn't correct |
25 |
Incorrect |
1099 ms |
164608 KB |
Output isn't correct |
26 |
Execution timed out |
2033 ms |
258044 KB |
Time limit exceeded |
27 |
Execution timed out |
2041 ms |
239764 KB |
Time limit exceeded |
28 |
Execution timed out |
2102 ms |
226568 KB |
Time limit exceeded |
29 |
Execution timed out |
2005 ms |
220316 KB |
Time limit exceeded |
30 |
Execution timed out |
2021 ms |
230096 KB |
Time limit exceeded |
31 |
Execution timed out |
2029 ms |
200100 KB |
Time limit exceeded |
32 |
Execution timed out |
2031 ms |
234932 KB |
Time limit exceeded |