#include <bits/stdc++.h>
using namespace std;
#define si short int
#define pii pair<si, si>
#define fi first
#define se second
pii dir[4]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pii> vec, tmp;
char a[4001][4001];
si n, m, ans;
void dfs(pii u)
{
char x=a[u.fi][u.se];
a[u.fi][u.se]='.';
for (pii i:dir)
{
pii v=u;
v.fi+=i.fi;
v.se+=i.se;
if (v.fi && v.fi<=n && v.se && v.se<=m && a[v.fi][v.se]!='.')
{
if (a[v.fi][v.se]==x)
dfs(v);
else
tmp.push_back(v);
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (si i=1; i<=n; i++)
for (si j=1; j<=m; j++)
cin >> a[i][j];
tmp.push_back({1, 1});
while (!tmp.empty())
{
vec=tmp;
tmp.clear();
for (pii u:vec)
dfs(u);
ans++;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
9 ms |
3668 KB |
Output is correct |
5 |
Correct |
3 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
584 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
1364 KB |
Output is correct |
11 |
Correct |
3 ms |
1748 KB |
Output is correct |
12 |
Correct |
8 ms |
1748 KB |
Output is correct |
13 |
Correct |
3 ms |
1492 KB |
Output is correct |
14 |
Correct |
3 ms |
1492 KB |
Output is correct |
15 |
Correct |
16 ms |
2636 KB |
Output is correct |
16 |
Correct |
21 ms |
2804 KB |
Output is correct |
17 |
Correct |
11 ms |
2512 KB |
Output is correct |
18 |
Correct |
10 ms |
3668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15684 KB |
Output is correct |
2 |
Correct |
54 ms |
5784 KB |
Output is correct |
3 |
Incorrect |
344 ms |
17052 KB |
Output isn't correct |
4 |
Correct |
78 ms |
8396 KB |
Output is correct |
5 |
Incorrect |
231 ms |
12836 KB |
Output isn't correct |
6 |
Correct |
807 ms |
77928 KB |
Output is correct |
7 |
Correct |
8 ms |
16340 KB |
Output is correct |
8 |
Correct |
10 ms |
15644 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
8 ms |
16004 KB |
Output is correct |
12 |
Correct |
1 ms |
952 KB |
Output is correct |
13 |
Correct |
52 ms |
5792 KB |
Output is correct |
14 |
Correct |
35 ms |
4396 KB |
Output is correct |
15 |
Incorrect |
25 ms |
4692 KB |
Output isn't correct |
16 |
Correct |
30 ms |
2388 KB |
Output is correct |
17 |
Correct |
133 ms |
8892 KB |
Output is correct |
18 |
Incorrect |
87 ms |
8736 KB |
Output isn't correct |
19 |
Correct |
71 ms |
8252 KB |
Output is correct |
20 |
Incorrect |
86 ms |
7728 KB |
Output isn't correct |
21 |
Incorrect |
202 ms |
13076 KB |
Output isn't correct |
22 |
Incorrect |
227 ms |
12828 KB |
Output isn't correct |
23 |
Correct |
262 ms |
10920 KB |
Output is correct |
24 |
Incorrect |
190 ms |
13260 KB |
Output isn't correct |
25 |
Incorrect |
388 ms |
16932 KB |
Output isn't correct |
26 |
Runtime error |
686 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Correct |
735 ms |
281964 KB |
Output is correct |
28 |
Correct |
798 ms |
77508 KB |
Output is correct |
29 |
Correct |
770 ms |
66524 KB |
Output is correct |
30 |
Correct |
788 ms |
159876 KB |
Output is correct |
31 |
Correct |
769 ms |
15244 KB |
Output is correct |
32 |
Correct |
718 ms |
315752 KB |
Output is correct |