작성
·
262
0
저는 강사님과는 반대로
배열을 1로 다 채운다음
받은 정사각형 만큼 0으로 바꾸었는데요
어디서 잘못되어서 문제가 풀리지않을까요? ㅠㅠ
#include <bits/stdc++.h>
using namespace std;
#define y1 aaaa
int adj[104][104], visited [104][104];
vector<int> v;
int n,m,k,x,y,nx,ny,res,x1,x2,y1,y2;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, 1, 0, -1};
int dfs(int y,int x){
visited[y][x]= 1;
int cnt=1;
for(int i=0;i<4;i++){
ny = y +dy[i];
nx = x +dx[i];
if(nx<0||ny<0||ny>=m||nx>=n)continue;
if(visited[ny][nx]==0 && adj[ny][nx]==1){
cnt+=dfs(ny,nx);
}else{
continue;
}
}
return cnt;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> m >> n >> k;
fill(&adj[0][0],&adj[0][0]+m*n,1);
for(int i=0;i<k;i++){
cin >> x1 >> y1 >> x2 >>y2;
for(int x = x1;x<x2;x++){
for(int y = y1; y<y2; y++){
adj[y][x]=0;
}
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(visited[i][j]==0 && adj[i][j]==1){
res++;
v.push_back(dfs(i,j));
}
}
}
sort(v.begin(),v.end());
cout << res << endl;
for(auto z: v){
cout << z << endl;
}
return 0;
}