#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<string> mat(n);
for (string& s : mat) {
cin >> s;
s.resize(n);
}
int di[]{0, 0, -1, 1};
int dj[]{-1, 1, 0, 0};
vector vis(n, vector<bool>(m));
int cnt = 0, res = 0;
auto dfs = [&](auto& dfs, int i, int j, int d)->void {
res = max(res, d);
cnt++;
//if (!(cnt & (1<<20)-1)) cout << cnt << endl;
vis[i][j] = 1;
for (int d = 0; d < 4; d++) {
int ei = i + di[d];
int ej = j + dj[d];
if (0 <= ei && ei < n && 0 <= ej && ej < m && !vis[ei][ej] && mat[ei][ej] == mat[i][j]) {
dfs(dfs, ei, ej, d);
}
}
for (int d = 0; d < 4; d++) {
int ei = i + di[d];
int ej = j + dj[d];
if (0 <= ei && ei < n && 0 <= ej && ej < m && !vis[ei][ej] && mat[ei][ej] == mat[i][j]) {
dfs(dfs, ei, ej, d+1);
}
}
};
dfs(dfs, 0, 0, 1);
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
1620 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
552 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
972 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
18 |
Incorrect |
4 ms |
1620 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
15316 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
3384 KB |
Output isn't correct |
3 |
Incorrect |
31 ms |
21944 KB |
Output isn't correct |
4 |
Incorrect |
8 ms |
5796 KB |
Output isn't correct |
5 |
Incorrect |
17 ms |
12356 KB |
Output isn't correct |
6 |
Incorrect |
177 ms |
51012 KB |
Output isn't correct |
7 |
Incorrect |
11 ms |
16732 KB |
Output isn't correct |
8 |
Incorrect |
10 ms |
15360 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Incorrect |
9 ms |
16080 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
4 ms |
2776 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
1996 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
2004 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
1488 KB |
Output isn't correct |
17 |
Incorrect |
10 ms |
9464 KB |
Output isn't correct |
18 |
Incorrect |
8 ms |
5768 KB |
Output isn't correct |
19 |
Incorrect |
7 ms |
5448 KB |
Output isn't correct |
20 |
Incorrect |
7 ms |
5064 KB |
Output isn't correct |
21 |
Incorrect |
19 ms |
19984 KB |
Output isn't correct |
22 |
Incorrect |
15 ms |
12096 KB |
Output isn't correct |
23 |
Incorrect |
17 ms |
10516 KB |
Output isn't correct |
24 |
Incorrect |
21 ms |
19744 KB |
Output isn't correct |
25 |
Incorrect |
26 ms |
21104 KB |
Output isn't correct |
26 |
Incorrect |
917 ms |
975012 KB |
Output isn't correct |
27 |
Incorrect |
572 ms |
376956 KB |
Output isn't correct |
28 |
Incorrect |
170 ms |
50752 KB |
Output isn't correct |
29 |
Incorrect |
204 ms |
82716 KB |
Output isn't correct |
30 |
Incorrect |
200 ms |
52560 KB |
Output isn't correct |
31 |
Incorrect |
17 ms |
13652 KB |
Output isn't correct |
32 |
Incorrect |
23 ms |
20800 KB |
Output isn't correct |