이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5;
const int maxn = 2503;
int dx[] = {+1, 0, -1, 0};
int dy[] = {0, -1, 0, +1};
int n, m;
int a[maxn][maxn];
int vis[maxn][maxn];
int tmp[maxn][maxn];
int cnt = 0;
int mnx, mxx, mny, mxy;
void dfs(int x, int y) {
tmp[x][y] = 1;
cnt++;
vis[x][y] = 1;
mnx = min(mnx, x);
mxx = max(mxx, x);
mny = min(mny, y);
mxy = max(mxy, y);
for(int i = 0; i < 4; i++) {
int xx = dx[i] + x;
int yy = dy[i] + y;
if(1 <= xx and xx <= n and 1 <= yy and yy <= m and a[xx][yy] == 0 and !vis[xx][yy]) {
dfs(xx, yy);
}
}
}
long long count_rectangles(vector<vector<int> > aa) {
n = aa.size(), m = aa[0].size();
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
a[i + 1][j + 1] = aa[i][j];
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(!vis[i][j] and a[i][j] == 0) {
mnx = inf, mxx = -inf;
mny = inf, mxy = -inf;
cnt = 0;
memset(tmp, 0, sizeof tmp);
dfs(i, j);
if((mxx - mnx + 1) * (mxy - mny + 1) == cnt and mnx != 1 and mxx != n and mny != 1 and mxy != m) {
ans++;
}
}
}
} 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... |