#include "rect.h"
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n, m;
vector<vector<int> > gr, vis;
vector<array<int, 2> > dir(4);
int x11, x22, y11, y22, cnt;
void dfs(int x, int y) {
if(vis[x][y] || gr[x][y]) return;
// cout << "x : " << x << " y:" << y << "\n";
cnt++;
vis[x][y] = 1;
x11 = min(x11, x);
x22 = max(x22, x);
y11 = min(y11, y);
y22 = max(y22, y);
for(auto c : dir) {
int xn = x + c[0], yn = y + c[1];
if(xn >= n || yn >= m) continue;
if(xn < 0 || yn < 0) continue;
dfs(xn, yn);
}
}
long long count_rectangles(std::vector<std::vector<int> > a) {
dir.resize(4);
dir[0] = {0, 1};
dir[1] = {0, -1};
dir[2] = {1, 0};
dir[3] = {-1, 0};
n = (int)a.size();
m = (int)a[0].size();
gr.assign(n, vector<int>(m, 0));
REP(i, n) REP(j, m) gr[i][j] = a[i][j];
vis.assign(n, vector<int>(m, 0));
lli ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
// cout << "i:" << i << " j:" << j << "\n";
if(vis[i][j] || gr[i][j]) continue;
x11 = i; x22 = i; y11 = j; y22 = j;
cnt = 0;
dfs(i, j);
if(cnt == 0) continue;
// cout << "x1:" << x11 << " x2:" << x22 << " y1:" << y11 << " y2:" << y22 << "\n";
if(x11 == 0 || y11 == 0 || x22 == n - 1 || y22 == m - 1) continue;
if((x22 - x11 + 1) * (y22 - y11 + 1) != cnt) continue;
ans++;
}
}
return ans;
}
// int main() {
// int n, m;
// cin >> n >> m;
// vector<vector<int> > grid(n,vector<int>(m));
// REP(i, n) REP(j, m) {
// cin >> grid[i][j];
// }
// cout << count_rectangles(grid) << "\n";
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
87 ms |
45436 KB |
Output is correct |
3 |
Correct |
207 ms |
98132 KB |
Output is correct |
4 |
Correct |
194 ms |
98440 KB |
Output is correct |
5 |
Correct |
191 ms |
98420 KB |
Output is correct |
6 |
Correct |
146 ms |
133200 KB |
Output is correct |
7 |
Correct |
303 ms |
308048 KB |
Output is correct |
8 |
Correct |
330 ms |
361112 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |