# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
867315 | sleepntsheep | Emacs (COCI20_emacs) | C++17 | 1 ms | 860 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |