# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883803 | vjudge1 | Emacs (COCI20_emacs) | C++17 | 1 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
const int N = 10001;
vi dad(N);
int find(int x) {
if (x == dad[x]) return x;
return dad[x] = find(dad[x]);
}
void unite(int x,int y) {
dad[find(x)] = find(y);
}
void solve() {
int n,m;
cin >> n >> m;
char grid[n+1][m+1];
F(i,n){
F(j,m) cin >> grid[i][j];
}
F(i,n*m) dad[i] = i;
for (int i=1;i<=n;i++) {
F(j,m) {
if (grid[i][j] == '*') {
if (i<n && grid[i+1][j] == '*') unite((i-1)*m+j,i*m+j);
if (j<m && grid[i][j+1] == '*') unite((i-1)*m+j,(i-1)*m+j+1);
}
}
}
set<int> s;
F(i,n) F(j,m) if (grid[i][j] == '*') s.insert(find((i-1)*m+j));
cout << s.size() << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |