# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867315 | sleepntsheep | Emacs (COCI20_emacs) | C++17 | 1 ms | 860 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 <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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |