#include "rect.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
int N,M;
vvi arr;
ll ans = 0;
void dfs(int a,int b){
if(arr[a][b] == 1)return;
queue<pi> pq;
pq.push({a,b});
vi r(N,0),c(M,0);
bool can = true;
int row = 0,column = 0,rowc = 0,colc = 0;
// cout << a << " " << b << endl;
while(!pq.empty()){
pi node = pq.front();pq.pop();
bool cans = true;
if(node.F == 0 && arr[node.F][node.S] == 0)cans = false;
if(node.S == 0 && arr[node.F][node.S] == 0)cans = false;
if(node.F == (N-1) && arr[node.F][node.S] == 0)cans = false;
if(node.S == (M-1) && arr[node.F][node.S] == 0)cans = false;
if(!cans){
can = false;
}
if(node.F > 0 && node.F < (N-1) && node.S > 0 && node.S < (M-1) && arr[node.F][node.S] == 0){
if(cans)arr[node.F][node.S] = 1;
r[node.F] += 1;
c[node.S] += 1;
pq.push({node.F-1,node.S});
pq.push({node.F+1,node.S});
pq.push({node.F,node.S-1});
pq.push({node.F,node.S+1});
}
}
FOR(i,0,N){
if(r[i] == 0)continue;
if(row!=0 && row!=r[i]){
can = false;
break;
}
row = r[i];
rowc++;
}
FOR(i,0,M){
if(can == false)break;
if(c[i] == 0)continue;
if(column!=0 && column!=c[i]){
can = false;
break;
}
column = c[i];
colc++;
}
// for(int i:r)cout << i << " ";
// cout << " - " << row << " - " << rowc << endl;
// for(int i:c)cout << i << " ";
// cout << " - " << column << " - " << colc << endl;
// cout << can << endl;
if(can){
ans += 1;
}
// for(auto as:arr){
// for(auto aas:as){{
// cout << aas << " ";
// }}cout << endl;
// }
// cout << endl;
}
ll count_rectangles(vvi a) {
N = a.size();M = a[0].size();
// cout << endl;
arr = a;
FOR(i,1,N-1){
FOR(j,1,M-1){
dfs(i,j);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 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 |
Incorrect |
1 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 |
4 ms |
532 KB |
Output is correct |
2 |
Correct |
3 ms |
520 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
398 ms |
33988 KB |
Output is correct |
3 |
Correct |
1103 ms |
73556 KB |
Output is correct |
4 |
Correct |
1124 ms |
74104 KB |
Output is correct |
5 |
Correct |
1040 ms |
74320 KB |
Output is correct |
6 |
Correct |
193 ms |
36700 KB |
Output is correct |
7 |
Correct |
327 ms |
69712 KB |
Output is correct |
8 |
Correct |
333 ms |
86320 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 |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |