Skip to content

Commit e63a99e

Browse files
authored
Merge pull request #1045 from AlgorithmWithGod/khj20006
[20251005] BOJ / G5 / paintbucket / 권혁준
2 parents 548d013 + 0301960 commit e63a99e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int N,M,A,B,a[1000][1000]{},v[1000][1000]{};
6+
int dx[4] = {1,0,-1,0};
7+
int dy[4] = {0,1,0,-1};
8+
9+
int main(){
10+
cin.tie(0)->sync_with_stdio(0);
11+
12+
cin>>M>>N>>B>>A;
13+
for(int i=0;i<N;i++) for(int j=0;j<M;j++) cin>>a[i][j];
14+
vector<pair<int,int>> r;
15+
queue<pair<int,int>> q;
16+
q.emplace(A,B);
17+
v[A][B]++;
18+
while(!q.empty()){
19+
auto [x,y] = q.front(); q.pop();
20+
r.emplace_back(x,y);
21+
for(int i=0;i<4;i++){
22+
int xx=x+dx[i], yy=y+dy[i];
23+
if(xx<0 || xx>=N || yy<0 || yy>=M || v[xx][yy] || a[xx][yy]!=a[A][B]) continue;
24+
q.emplace(xx,yy);
25+
v[xx][yy]++;
26+
}
27+
}
28+
sort(r.begin(),r.end());
29+
for(auto [x,y]:r) cout<<y<<' '<<x<<'\n';
30+
31+
}
32+
```

0 commit comments

Comments
 (0)