이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long count_rectangles(std::vector<std::vector<int>> a)
{
long long n = a.size();
long long m = a[0].size();
vector<vector<int>> explored(n);
for(int i = 0; i < n; i++) explored[i].resize(m);
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
explored[i][j] = 0;
vector<vector<int>> prefix(n+1);
for(int i = 0; i < n+1; i++) prefix[i].resize(m+1);
prefix[0][0] = 0;
for(int i = 0; i < n+1; i++) prefix[i][0] = 0;
for(int i = 0; i < m+1; i++) prefix[0][i] = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
a[i][j] = a[i][j] > 0;
prefix[i+1][j+1] = a[i][j];
prefix[i+1][j+1] += prefix[i][j+1];
prefix[i+1][j+1] += prefix[i+1][j];
prefix[i+1][j+1] -= prefix[i][j];
}
}
long long res = 0;
for(long long i = 1; i < n-1; i++){
for(long long j = 1; j < m-1; j++){
if(explored[i][j]) continue;
explored[i][j] = 1;
if(a[i][j] > 0){
continue;
}
long long endX = i;
long long endY = j;
while(endX < n-2 && a[endX+1][endY] == 0){
endX++;
explored[endX][j] = 1;
}
while(endY < m-2 && a[endX][endY+1] == 0){
endY++;
for(int u = i; u <= endX; u++){
explored[u][endY] = 1;
}
}
if(prefix[endX+1][endY+1] + prefix[i-1+1][j-1+1] - prefix[i-1+1][endY+1]-prefix[endX+1][j-1+1] != 0) continue;
long long nbOnes = 0;
nbOnes += prefix[endX+2][endY+2] + prefix[i-1][j-1] - prefix[i-1][endY+2]-prefix[endX+2][j-1];
nbOnes -= prefix[endX+1][endY+1] + prefix[i-1+1][j-1+1] - prefix[i-1+1][endY+1]-prefix[endX+1][j-1+1];
nbOnes -= a[i-1][j-1];
nbOnes -= a[endX+1][j-1];
nbOnes -= a[i-1][endY+1];
nbOnes -= a[endX+1][endY+1];
if(nbOnes == 2*(endX-i+1) + 2*(endY-j+1)){
res++;
}
}
}
return res;
}
# | 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... |