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 "rect.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using matrix = vector<vector<T>>;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
struct cebola{
int pai;
int minx, maxx, miny, maxy;
int sz;
};
long long count_rectangles(std::vector<std::vector<int> > a) {
int n = a.size(), m = a[0].size();
int tot = n*m;
vector<cebola> v(tot);
for(int i = 0; i < tot; i++){
v[i] = {i,tot%m,tot%m,tot/m,tot/m,1};
}
auto find =[&](int id, auto find){
if(v[id].pai == id)
return id;
return v[id].pai = find(v[id].pai,find);
};
auto onion =[&](int a, int b){
a= find(a,find);
b = find(b,find);
if(a == b)
return;
v[a].pai = b;
v[b].minx = min(v[b].minx,v[a].minx);
v[b].miny = min(v[b].miny,v[a].miny);
v[b].maxx = max(v[b].maxx,v[a].maxx);
v[b].maxy = max(v[b].maxy,v[a].maxy);
};
int dx[]{1,0,-1,0}, dy[]{0,1,0,-1};
for(int i = 0; i < tot; i++){
int x = i%m, y = i/m;
for(int j = 0; j < 4; j++){
int xi = x + dx[i], yi = dy[i];
if(xi < 0 || xi >= m || yi < 0 || yi >= n){
continue;
}
int id = yi*m+xi;
if(a[y][x] == 0 && a[yi][xi] == 0)
onion(i,id);
}
}
int resp = 0;
for(int i = 0; i < tot; i++){
int x = i%m, y = i/m;
if(a[y][x] != 0 || v[i].pai != i)
continue;
if(v[i].maxx == m-1 || v[i].minx == 0 || v[i].miny == 0 || v[i].maxy == n-1)
continue;
resp++;
}
return resp;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |