#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
void PlayGround() {
int r, c; cin >> r >> c;
vector<string>g(r);
for(string& row : g) cin >> row;
vector<vector<bool>>vis(r, vector<bool>(c));
int ans = 0;
auto valid = [&] (int i, int j) {
return i>-1 && i<r && j>-1 && j<c && vis[i][j]==false;
};
auto BFS = [&] (int x, int y) {
int dx[] {1, -1, 0, 0};
int dy[] {0, 0, 1, -1};
queue<pair<int,int>>q;
q.push(make_pair(x, y));
while(!q.empty()) {
int i = q.front().first, j = q.front().second;
q.pop();
if(vis[i][j]) continue;
vis[i][j] = true;
for(int k=0; k<4; ++k) {
int newi = i + dx[k], newj = j + dy[k];
if(valid(newi, newj) && g[newi][newj]==g[i][j])
q.push(make_pair(newi, newj));
}
}
};
for(int i=0; i<r; ++i) {
for(int j=0; j<c; ++j) if(!vis[i][j] && g[i][j]!='*') {
BFS(i, j);
++ans;
}
}
cout << ans << '\n';
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// #endif
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |