# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
234313 | UserIsUndefined | Rectangles (IOI19_rect) | C++14 | 5 ms | 512 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;
/*
for (int i = 1 ; i < n - 1 ; i++){
for (int j = 1 ; j < m - 1 ; j++){
int limitTol = n - 1;
int limitArad = m - 1;
for (int tol = 1 ; tol + i - 1 < limitTol ; tol++){
for (int arad = 1 ; arad + j - 1 < limitArad ; arad++){
int r1 = i, r2 = i + tol, c1 = j, c2 = j + arad;
bool ok = false;
for (int row = r1 ; row < r2 ; row++){
for (int cal = c1 ; cal < c2 ; cal++){
if (a[row][cal] < a[r1 - 1][cal] && a[row][cal] < a[row][c1 - 1] && a[row][cal] < a[r2][cal] && a[row][cal] < a[row][c2]){
continue;
}
else {
if (a[row][cal] >= a[r1 - 1][cal] || a[row][cal] >= a[row][c1 - 1])limitArad = cal;
ok = true;
break;
}
}
if (ok)break;
}
if (ok == false)ans++;
}
}
}
}
*/
vector<pair<int,int>> zeros;
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 = 0 ; i < n ; i++){
if (i == 0)presum[i][j] = presum[i][j];
else presum[i][j] = presum[i-1][j] + presum[i][j];
}
}
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++){
for (int j = i ; j < zeros.size() ; j++){
if (zeros[j].first < zeros[i].first || zeros[j].second < zeros[i].second)continue;
int big = presum[zeros[j].first][zeros[j].second];
int small = presum[zeros[i].first - 1][zeros[i].second - 1];
int first = presum[zeros[j].first][zeros[i].second - 1];
int second = presum[zeros[i].first-1][zeros[j].second];
// cout << "from " << "(" << zeros[i].first << "," << zeros[i].second << ") to (" << zeros[j].first << "," << zeros[j].second << ")" <<endl;
int sum = big - first - second + small;
// cout << "sum = " << sum << endl;
if (sum == 0)ans++;
}
}
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... |