# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030936 | fv3 | Rectangles (IOI19_rect) | C++14 | 83 ms | 50000 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>
using namespace std;
using namespace std;
typedef long long ll;
int N, M;
int l, r, t, d, cnt;
vector<vector<int>> grid, visited;
void DFS(int x, int y)
{
visited[y][x] = 1; cnt++;
l < min(l, x); r = max(r, x);
t < min(t, y); d = max(d, y);
if (x && !grid[y][x-1] && !visited[y][x-1])
DFS(x-1, y);
if (y && !grid[y-1][x] && !visited[y-1][x])
DFS(x, y-1);
if (x+1!=M && !grid[y][x+1] && !visited[y][x+1])
DFS(x+1, y);
if (y+1!=N && !grid[y+1][x] && !visited[y+1][x])
DFS(x, y+1);
}
ll count_rectangles(vector<vector<int>> a)
{
N = a.size();
M = a[0].size();
if (N < 3 || M < 3)
return 0;
grid = a;
visited = vector<vector<int>>(N, vector<int>(M));
ll res = 0;
for (int y = 1; y < N-1; y++)
{
for (int x = 1; x < M-1; x++)
{
if (visited[y][x] || grid[y][x]) continue;
l = r = x;
t = d = y;
cnt = 0;
DFS(x, y);
if (cnt == (r - l + 1) * (d - t + 1) && l && t && d < N-1 && r < M-1)
res++;
}
}
return res;
}
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... |