#include <bits/stdc++.h>
#include "rect.h"
#define all(x) x.begin(),x.end()
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 2600;
const int oo = 2e9;
bool mrk[N][N];
int n, m, kol = 0, mx, my, Mx, My;
ll ans = 0;
void dfs(int x, int y){
if (mrk[x][y]) return;
kol++;
mrk[x][y] = 1;
mx = min(mx, x);
my = min(my, y);
Mx = max(Mx, x);
My = max(My, y);
if (x > 0) dfs(x - 1, y);
if (y > 0) dfs(x, y - 1);
if (y < m - 1) dfs(x, y + 1);
if (y < n - 1) dfs(x + 1, y);
}
long long count_rectangles(std::vector<std::vector<int> > a) {
n = sz(a);
m = sz(a[0]);
if (n < 3 || m < 3) return 0;
bool ok = 1;
for (int i = 0; i < n && ok; i++)
for (int j = 0; j < m && ok; j++) {
ok &= bool(a[i][j] < 2);
mrk[i][j] = a[i][j];
}
if (ok){
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (!mrk[i][j]){
mx = my = oo;
Mx = My = -oo;
kol = 0;
dfs(i, j);
if ((Mx - mx + 1) * (My - my + 1) == kol)
ans++;
}
return ans;
}
for (int r1 = 1; r1 < n - 1; r1++)
for (int r2 = r1; r2 < n - 1; r2++)
for (int c1 = 1; c1 < m - 1; c1++)
for (int c2 = c1; c2 < m - 1; c2++){
bool ok = 1;
for (int i = r1; i <= r2 && ok; i++)
for (int j = c1; j <= c2 && ok; j++){
ok &= bool(a[i][j] < a[i][c1 - 1]);
ok &= bool(a[i][j] < a[i][c2 + 1]);
ok &= bool(a[i][j] < a[r2 + 1][j]);
ok &= bool(a[i][j] < a[r1 - 1][j]);
}
ans += ok;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Runtime error |
22 ms |
20736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Runtime error |
22 ms |
20736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Runtime error |
22 ms |
20736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Runtime error |
22 ms |
20736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
488 KB |
Output is correct |
2 |
Correct |
21 ms |
512 KB |
Output is correct |
3 |
Correct |
97 ms |
7288 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
26 ms |
384 KB |
Output is correct |
6 |
Correct |
28 ms |
512 KB |
Output is correct |
7 |
Correct |
26 ms |
544 KB |
Output is correct |
8 |
Correct |
25 ms |
384 KB |
Output is correct |
9 |
Correct |
26 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
15744 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Runtime error |
22 ms |
20736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |