10000 Update 2667.cpp · SooYeonida/basic-algo-lecture@baea0cc · GitHub
[go: up one dir, main page]

Skip to content

Commit baea0cc

Browse files
committed
Update 2667.cpp
1 parent 837c83c commit baea0cc

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

0x09/solutions/2667.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : 0silver00
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/118e3a5900f94c4aae7aff09c263ef06
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 n;
12+
string board[27];
13+
int vis[27][27];
14+
715
int main(void){
816
ios::sync_with_stdio(0);
917
cin.tie(0);
10-
18+
19+
cin >> n;
20+
for(int i = 0; i < n; i++) {
21+
cin >> board[i];
22+
}
23+
24+
int count = 0;
25+
vector <int> ans;
26+
27+
for (int i = 0; i < n; i++) {
28+
for (int j = 0; j < n; j++) {
29+
if (board[i][j] == '0' || vis[i][j] == 1)
30+
continue;
31+
queue < pair<int, int> > Q;
32+
vis[i][j] = 1;
33+
Q.push({ i, j });
34+
int width = 1;
35+
count++;
36+
while (!Q.empty()) {
37+
auto cur = Q.front();
38+
Q.pop();
39+
for (int dir = 0; dir < 4; dir++) {
40+
int nx = cur.X + dx[dir];
41+
int ny = cur.Y + dy[dir];
42+
if (nx < 0 || nx >= n || ny < 0 || ny >= n)
43+
continue;
44+
if (board[nx][ny] == '0' || vis[nx][ny] == 1)
45+
continue;
46+
Q.push({ nx, ny });
47+
vis[nx][ny] = 1;
48+
width++;
49+
}
50+
}
51+
ans.push_back(width);
52+
}
53+
}
54+
55+
cout << count << '\n';
56+
sort(ans.begin(), ans.end());
57+
58+
for (int i : ans)
59+
cout << i << '\n';
60+
61+
return 0;
1162
}

0 commit comments

Comments
 (0)
0