8000 Merge pull request #115 from 0silver00/0silver00 · shine-jung/basic-algo-lecture@c8b23f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8b23f7

Browse files
Merge pull request encrypted-def#115 from 0silver00/0silver00
0silver00
2 parents eaebf5f + 837c83c commit c8b23f7

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

0x09/solutions/2583.cpp

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,65 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
2-
// Co-authored by : -
3-
// http://boj.kr/****************
1+
// Authored by : 0silver00
2+
// Co-authored by : BaaaaaaaaaaarkingDog
3+
// http://boj.kr/d0c205b6ead644d896fec013b6e64129
44
#include <bits/stdc++.h>
55
using namespace std;
66

7+
#define X first
8+
#define Y second
9+
int dx[4] = { 1, 0, -1, 0 };
10+
int dy[4] = { 0, 1, 0, -1 };
11+
int m, n, k;
12+
int board[102][102];
13+
int vis[102][102];
14+
715
int main(void){
816
ios::sync_with_stdio(0);
917
cin.tie(0);
10-
11-
}
18+
19+
cin >> m >> n >> k;
20+
while (k--) {
21+
int x1, y1, x2, y2;
22+
cin >> x1 >> y1 >> x2 >> y2;
23+
for (int j = y1; j < y2; j++)
24+
for (int k = x1; k < x2; k++)
25+
board[j][k] = 1;
26+
}
27+
28+
int count = 0;
29+
vector<int> ans;
30+
31+
for (int i = 0; i < m; i++) {
32+
for (int j = 0; j < n; j++) {
33+
if (board[i][j] == 1 || vis[i][j] == 1)
34+
continue;
35+
queue<pair<int, int>> Q;
36+
vis[i][j] = 1;
37+
Q.push({ i, j });
38+
int width = 1;
39+
count++;
40+
while (!Q.empty()) {
41+
auto cur = Q.front();
42+
Q.pop();
43+
for (int dir = 0; dir < 4; dir++) {
44+
int nx = cur.X + dx[dir];
45+
int ny = cur.Y + dy[dir];
46+
if (nx < 0 || nx >= m || ny < 0 || ny >= n)
47+
continue;
48+
if (board[nx][ny] == 1 || vis[nx][ny] == 1)
49+
continue;
50+
Q.push({ nx, ny });
51+
vis[nx][ny] = 1;
52+
width++;
53+
}
54+
}
55+
ans.push_back(width);
56+
}
57+
}
58+
sort(ans.begin(), ans.end());
59+
60+
cout << count << '\n';
61+
for (int i : ans)
62+
cout << i << ' ';
63+
64+
return 0;
65+
}

0 commit comments

Comments
 (0)
0