# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
235068 | UserIsUndefined | Rectangles (IOI19_rect) | C++14 | 5078 ms | 54112 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 "rect.h"
#include <bits/stdc++.h>
int presum[3000][3000];
using namespace std;
long long count_rectangles(std::vector<std::vector<int> > a) {
int n = a.size();
int m = a[0].size();
long long ans = 0;
// cout << "AAA" << endl;
for (int i = 0 ; i < n ; i++){
for (int j = 0 ; j < m ; j++){
if (j == 0)presum[i][j] = a[i][j];
else presum[i][j] = presum[i][j-1] + a[i][j];
}
}
for (int j = 0 ; j < m ; j++){
for (int i = 1 ; i < n ; i++){
presum[i][j] = presum[i - 1][j] + presum[i][j];
}
}
vector<pair<int,int>> zeros;
for (int i = 1 ; i < n - 1 ; i++){
for (int j = 1 ; j < m - 1 ; j++){
if (a[i][j] == 0)zeros.push_back({i,j});
}
}
for (int i = 0 ; i < zeros.size() ; i++){
int x0,y0,x1,y1;
x0 = zeros[i].first; y0 = zeros[i].second ;
for (int x1 = x0 ; x1 < n - 1 ; x1++){
for (int y1 = y0 ; y1 < m - 1 ; y1++){
if (a[x1][y1] == 1)continue;
int big0, small0, rec01, rec02, sum0;
big0 = presum[x1][y1];
small0 = presum[x0 - 1][y0 - 1];
rec01 = presum[x1][y0 - 1];
rec02 = presum[x0 - 1][y1];
sum0 = big0 - rec01 - rec02 + small0;
if (sum0 != 0)continue;
big0 = presum[x1 + 1][y1 + 1];
small0 = (x0 == 1 || y0 == 1 ? 0 : presum[x0 - 2][y0 - 2]);
rec01 = (y0 == 1 ? 0 : presum[x1 + 1][y0 - 2]);
rec02 = (x0 == 1 ? 0 : presum[x0 - 2][y1 + 1]);
sum0 = big0 - rec01 - rec02 + small0;
int atfirst = sum0;
sum0-= (a[x1 + 1][y1 + 1] == 1 ? 1 : 0);
sum0-= (a[x0 - 1][y0 - 1] == 1 ? 1 : 0);
sum0-= (a[x1 + 1][y0 - 1] == 1? 1 : 0);
sum0-= (a[x0 - 1][y1 + 1] == 1? 1 : 0);
int should = x1 - x0 + 1;
should+= (y1 - y0 + 1);
should*= 2;
if (sum0 == should){
ans++;
// cout << "from (" << x0 << "," << y0 << ") to (" << x1 << "," << y1 << endl;
// cout << "should =" << should << endl;
// cout << "at first = " << atfirst << endl;
}
}
}
}
return 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |