이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
long long count_rectangles(vector<vector<int> > a)
{
int n = a.size();
int m = a[0].size();
vector<vector<int> >viz(n, vector<int>(m));
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
viz[i][j] = 0;
int max_val = 0;
int min_val = (1<<30);
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
{
max_val = max(max_val, a[i][j]);
min_val = min(min_val, a[i][j]);
}
if(max_val == min_val)
return 0;
long long ans = 0;
if(max_val == 1)
{
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
{
if(a[i][j] == 0 && !viz[i][j])
{
int minix = i, maxix = i, miniy = j, maxiy = j;
int cnt = 1;
viz[i][j] = 1;
deque<pair<int, int> >d;
d.push_back({i, j});
while(!d.empty())
{
pair<int, int> nod = d[0];
d.pop_front();
for(int ox = -1; ox <= 1; ++ox)
for(int oy = -1; oy <= 1; ++oy)
{
if(ox && oy)
continue;
if(!ox && !oy)
continue;
int new_x = nod.first + ox;
int new_y = nod.second + oy;
if(new_x >= 0 && new_y >= 0 && new_x < n && new_y < m)
{
if(a[new_x][new_y] == 0 && !viz[new_x][new_y])
{
viz[new_x][new_y] = 1;
d.push_back({new_x, new_y});
minix = min(minix, new_x);
maxix = max(maxix, new_x);
miniy = min(miniy, new_y);
maxiy = max(maxiy, new_y);
++cnt;
}
}
}
}
if(minix && miniy && maxix < n-1 && maxiy < m-1)
{
if(cnt == (maxix - minix + 1) * (maxiy - miniy + 1))
++ans;
}
}
}
}
return ans;
}
# | 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... |