이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
#include "rect.h"
int dirX[4] = {-1, 1, 0, 0};
int dirY[4] = {0, 0, -1, 1};
int N, M;
int grid[2505][2505];
bool vis[2505][2505];
int tpt, bpt, lpt, rpt;
// tpt = top, bpt = bottom, lpt = left, rpt = right
int compsize = 0;
void dfs(int x, int y) {
tpt = max(tpt, x);
bpt = min(bpt, x);
rpt = max(rpt, y);
lpt = min(lpt, y);
compsize++;
vis[x][y] = true;
for (int i = 0; i < 4; i++) {
int newX = x + dirX[i];
int newY = y + dirY[i];
if (newX < 0 || newX >= N)
continue;
if (newY < 0 || newY >= M)
continue;
if (grid[newX][newY] == 0 && !vis[newX][newY])
dfs(newX, newY);
}
}
ll count_rectangles(vector<vi> a) {
N = a.size();
M = a[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
grid[i][j] = a[i][j];
}
}
ll total = 0;
for (int i = 0; i <= N - 1; i++) {
for (int j = 0; j <= M - 1; j++) {
if (grid[i][j] == 0 && !vis[i][j]) {
tpt = -1;
bpt = 1e9;
rpt = -1;
lpt = 1e9;
compsize = 0;
dfs(i, j);
if (bpt == 0 || tpt == N - 1)
continue;
if (lpt == 0 || rpt == M - 1)
continue;
if (compsize == (tpt - bpt + 1) * (rpt - lpt + 1)) {
// cout<<"good "<<i<<" "<<j<<endl;
total++;
}
}
}
}
return total;
}
# | 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... |