#include<bits/stdc++.h>
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
using namespace std;
const ll MOD=1e9+7;
// mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
int n, m, ans;
char a[4005][4005];
bool used[4005][4005];
void dfs(int x, int y)
{
used[x][y]=1;
if(x+1<n and a[x+1][y]==a[x][y] and !used[x+1][y]) dfs(x+1, y);
if(x-1>=0 and a[x-1][y]==a[x][y] and !used[x-1][y]) dfs(x-1, y);
if(y+1<m and a[x][y+1]==a[x][y] and !used[x][y+1]) dfs(x, y+1);
if(y-1>=0 and a[x][y-1]==a[x][y] and !used[x][y-1]) dfs(x, y-1);
}
int main()
{
SPEED;
cin>>n>>m;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
cin>>a[i][j];
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
if(a[i][j]==a[0][0] and !used[i][j]) ans++, dfs(i, j);
}
cout<<ans+1<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
4264 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
4 |
Incorrect |
8 ms |
4896 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
2508 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
2252 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
2124 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
2636 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
2508 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
2508 KB |
Output isn't correct |
15 |
Incorrect |
10 ms |
4300 KB |
Output isn't correct |
16 |
Incorrect |
14 ms |
4260 KB |
Output isn't correct |
17 |
Incorrect |
8 ms |
4044 KB |
Output isn't correct |
18 |
Incorrect |
8 ms |
4940 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
30540 KB |
Output isn't correct |
2 |
Incorrect |
39 ms |
10180 KB |
Output isn't correct |
3 |
Incorrect |
349 ms |
32300 KB |
Output isn't correct |
4 |
Incorrect |
84 ms |
15296 KB |
Output isn't correct |
5 |
Incorrect |
171 ms |
24240 KB |
Output isn't correct |
6 |
Incorrect |
487 ms |
55716 KB |
Output isn't correct |
7 |
Incorrect |
21 ms |
31948 KB |
Output isn't correct |
8 |
Incorrect |
17 ms |
30540 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
716 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
11 |
Incorrect |
16 ms |
31360 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1484 KB |
Output isn't correct |
13 |
Incorrect |
40 ms |
10316 KB |
Output isn't correct |
14 |
Incorrect |
24 ms |
7500 KB |
Output isn't correct |
15 |
Incorrect |
24 ms |
8268 KB |
Output isn't correct |
16 |
Incorrect |
18 ms |
3656 KB |
Output isn't correct |
17 |
Incorrect |
94 ms |
16428 KB |
Output isn't correct |
18 |
Incorrect |
90 ms |
16400 KB |
Output isn't correct |
19 |
Incorrect |
76 ms |
15336 KB |
Output isn't correct |
20 |
Incorrect |
72 ms |
14344 KB |
Output isn't correct |
21 |
Incorrect |
190 ms |
25140 KB |
Output isn't correct |
22 |
Incorrect |
165 ms |
24192 KB |
Output isn't correct |
23 |
Incorrect |
187 ms |
20400 KB |
Output isn't correct |
24 |
Incorrect |
183 ms |
25304 KB |
Output isn't correct |
25 |
Incorrect |
355 ms |
32272 KB |
Output isn't correct |
26 |
Incorrect |
1272 ms |
986724 KB |
Output isn't correct |
27 |
Incorrect |
717 ms |
283000 KB |
Output isn't correct |
28 |
Incorrect |
489 ms |
56276 KB |
Output isn't correct |
29 |
Incorrect |
564 ms |
63652 KB |
Output isn't correct |
30 |
Incorrect |
432 ms |
57332 KB |
Output isn't correct |
31 |
Incorrect |
362 ms |
26564 KB |
Output isn't correct |
32 |
Incorrect |
304 ms |
32884 KB |
Output isn't correct |