Submission #883803

#TimeUsernameProblemLanguageResultExecution timeMemory
883803vjudge1Emacs (COCI20_emacs)C++17
50 / 50
1 ms600 KiB
#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 timeMemoryGrader output
Fetching results...