8000 Update 2583.cpp · SooYeonida/basic-algo-lecture@fff6d16 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fff6d16

Browse files
committed
Update 2583.cpp
1 parent eaebf5f commit fff6d16

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

0x09/solutions/2583.cpp

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,65 @@
11
// Authored by : BaaaaaaaaaaarkingDog
2-
// Co-authored by : -
3-
// http://boj.kr/****************
2+
// Co-authored by : 0silver00
3+
// http://boj.kr/7daa30318d98480985e402b4e3a14bc1
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 dist[102][102];
14+
715
int main(void){
816
ios::sync_with_stdio(0);
917
cin.tie(0);
10-
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 || dist[i][j] == 1)
34+
continue;
35+
queue<pair<int, int>> Q;
36+
dist[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 || dist[nx][ny] == 1)
49+
continue;
50+
Q.push({ nx, ny });
51+
dist[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;
1165
}

0 commit comments

Comments
 (0)
0