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>
using namespace std;
long long count_rectangles(std::vector<std::vector<int>> g){
int n = g.size(), m = g[0].size();
int ans = 0;
vector<pair<int, int>> res;
for (int i = 1; i < n; i++){
for (auto &[l, r]: res){
bool flag = 0;
for (int j = l; j <= r; j++)
flag |= g[i][j] == 0;
ans += !flag;
}
vector<pair<int, int>> tmp;
for (auto &[l, r]: res){
if (g[i][l - 1] == 1 && g[i][r + 1] == 1){
bool flag = 0;
for (int j = l; j <= r; j++)
flag |= g[i][j] == 1;
if (!flag)
tmp.emplace_back(l, r);
}
}
for (int j = 0; j < m - 1; ){
if (g[i][j] == 1){
j++;
int l = j, r = j;
while (r < m && g[i][r] == 0)
r++;
if (r == m) break;
r--;
if (i == 1 && l == 2 && r == 2)
cerr << "OK" << endl;
bool flag = 0;
for (; j <= r; j++)
flag |= g[i - 1][j] == 0;
if (!flag && l <= r)
tmp.emplace_back(l, r);
}else j++;
}
swap(res, tmp);
// cerr << i << endl;
// for (auto &[l, r]: res)
// cerr << l << ' ' << r << endl;
}
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... |