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"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
using namespace std;
const int MxN=2510;
int n, m, a[MxN][MxN];
bool st_node(int i, int j, int in) {
if(in==0) return a[i][j]==0 && a[i][j-1]==1 && a[i-1][j]==1 && a[i+1][j]==1;
return a[i][j]==0 && a[i-1][j]==1 && a[i][j-1]==1 && a[i][j+1]==1;
}
bool nd_node(int i, int j, int in) {
if(in==0) return a[i][j]==0 && a[i-1][j]==1 && a[i+1][j]==1 && a[i][j+1]==1;
return a[i][j]==0 && a[i+1][j]==1 && a[i][j-1]==1 && a[i][j+1]==1;
}
bool mid_node(int i, int j, int in) {
if(in==0) return a[i][j]==0 && a[i-1][j]==1 && a[i+1][j]==1;
return a[i][j]==0 && a[i][j-1]==1 && a[i][j+1]==1;
}
bool sqr(int i, int j) {
return a[i][j]==0 && a[i+1][j]==1 && a[i-1][j]==1 && a[i][j-1]==1 && a[i][j+1]==1;
}
long long count_rectangles(std::vector<std::vector<int> > A) {
n=A.size(); m=A[0].size();
FOR(i, 0, n) FOR(j, 0, m) a[i][j]=A[i][j];
int ans=0;
FOR(i, 1, n-1) FOR(j, 1, m-1) if(sqr(i, j)) ans++;
FOR(i, 1, n-1) {
bool started=false;
FOR(j, 1, m-1) {
if(st_node(i, j, 0)) {
started=true;
}
else if(nd_node(i, j, 0)) {
if(started) ans++;
}
else if(!mid_node(i, j, 0)) {
started=false;
}
}
}
FOR(j, 1, m-1) {
bool started=false;
FOR(i, 1, n-1) {
if(st_node(i, j, 1)) {
started=true;
}
else if(nd_node(i, j, 1)) {
if(started) ans++;
}
else if(!mid_node(i, j, 1)) {
started=false;
}
}
}
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... |