Submission #867315

#TimeUsernameProblemLanguageResultExecution timeMemory
867315sleepntsheepEmacs (COCI20_emacs)C++17
50 / 50
1 ms860 KiB
#include <iostream> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> using namespace std; #define ALL(x) x.begin(), x.end() using ll = long long; struct dsu { vector<int> p; dsu(int n) : p(n, -1) {} int find(int x) { return p[x] < 0 ? x : find(p[x]); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return 0; if (-p[x] > -p[y]) swap(x, y); p[y] += p[x]; p[x] = y; return 1; } bool same(int x, int y) { return find(x) == find(y); } }; #define N 105 int n, m, dx[]={-1,1,0,0},dy[]={0,0,1,-1}; char s[N][N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); dsu dsu(99999); cin >> n >> m; int cmp=0; for (int i = 1; i <= n; ++i) cin >> (&s[i][1]); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { if (s[i][j]=='*'){ ++cmp; for (int k=0;k<4;++k) { int ni=i+dy[k],nj=j+dx[k]; if (s[ni][nj]=='*') cmp-=dsu.unite(i*N+j, ni*N+nj); } } } cout << cmp; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...