# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
350123 | arnold518 | Raspad (COI17_raspad) | C++14 | 384 ms | 816 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
const int MAXM = 50;
int N, M;
int A[MAXN+10][MAXM+10];
struct UF
{
int par[MAXN*MAXM+10];
int Find(int x)
{
if(x==par[x]) return x;
return par[x]=Find(par[x]);
}
bool Union(int x, int y)
{
x=Find(x); y=Find(y);
if(x==y) return 0;
par[x]=y;
return 1;
}
}uf;
int f(int y, int x)
{
return (y-1)*M+(x-1);
}
ll ans=0;
int main()
{
scanf("%d%d", &N, &M);
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) scanf("%1d", &A[i][j]);
for(int i=1; i<=N; i++)
{
int val=0;
for(int j=i; j<=N; j++)
{
for(int k=1; k<=M; k++)
{
uf.par[f(j, k)]=f(j, k);
}
for(int k=1; k<=M; k++)
{
if(!A[j][k]) continue;
val++;
if(j!=i && A[j-1][k]) val-=uf.Union(f(j, k), f(j-1, k));
if(A[j][k-1]) val-=uf.Union(f(j, k), f(j, k-1));
}
//printf("%d %d : %d\n", i, j, val);
ans+=val;
}
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |