diff --git "a/s13121312/\352\265\254\355\230\204/14502.cpp" "b/s13121312/\352\265\254\355\230\204/14502.cpp" new file mode 100644 index 0000000..4c793fd --- /dev/null +++ "b/s13121312/\352\265\254\355\230\204/14502.cpp" @@ -0,0 +1,127 @@ +#include +using namespace std; +int n, m; +int arr[10][10]; +bool vis[10][10]; //벽 세워진적있던곳 체크 +int ans = 0; //안전 영역 최대 크기 +vector > builtwall; //벽으로 지정된 좌표 저장 +int dx[] = {1,0,-1, 0}; +int dy[] = {0, 1, 0, -1}; +int ansarr[10][10]; //디버깅용 정답 arr + + + +void input() { + cin >> n >>m; + for(int i=0;i> arr[i][j]; + } + } +} + +//바이러스 퍼뜨리기 +int bfs(int tmp[10][10]) { + + bool chk[10][10]; + for(int i=0;i > q; + q.push({i, j}); + chk[i][j] = true; + + while(!q.empty()) { + auto cur = q.front(); + q.pop(); + for(int d=0;d<4;d++) { + int nx = cur.first + dx[d]; + int ny = cur.second + dy[d]; + if(nx<0 || nx>=n || ny<0 || ny>=m)continue; + if(chk[nx][ny] || tmp[nx][ny] == 1)continue; + + tmp[nx][ny] = 2; + q.push({nx,ny}); + chk[nx][ny] = true; + } + } + } + } + } + + + int con = 0; + for(int i=0;i= n*m)return; + + if(arr[x][y] == 0) { + builtwall.push_back({x, y}); + buildwall(idx+1, depth+1); + builtwall.pop_back(); + } + //// 안 세우고 넘어가는 경우 + buildwall(idx+1, depth); + + +} + + +int main() { + + input(); + buildwall(0, 0); + cout << ans << '\n'; + // for(int i=0;i +using namespace std; +char arr[1005][1005]; +int n, m; +int dist[1005][1005][2]; +//[0] 벽을 하나도 안 부수고 (x,y)까지 오는데 걸리는 비용 +//[1] 벽을 하나만 부수고 (x,y)까지 오는데 걸리는 비용, (x,y)가 벽이라서 부수는 경우 포함 +int dx[] = {1,0,-1,0}; +int dy[] = {0,1,0,-1}; + +void input() { + cin >> n >> m; + for(int i=0;i> arr[i][j]; + } + } +} + +int bfs() { + + for(int i=0;i (n-1,m-1) + queue> q; + q.push({0, 0, 0}); + dist[0][0][0] = dist[0][0][1] = 1; + + while(!q.empty()) { + int x, y, broken; + tie(x,y,broken) = q.front(); + + if(x == n-1 && y ==m-1) { + return dist[x][y][broken]; + } + q.pop(); + int nxtdist = dist[x][y][broken] + 1; + for(int i=0;i<4;i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + if(nx<0 || nx>=n ||ny<0 || ny>=m)continue; + if(arr[nx][ny] == '0' && dist[nx][ny][broken] == -1) { //온적 없고 벽이아니면 + dist[nx][ny][broken] = nxtdist; + q.push({nx,ny,broken}); + } + if(!broken && arr[nx][ny] == '1' && dist[nx][ny][broken] == -1) { // broken이 0(벽을 한 번도 한 부숨) 다음에 갈게 벽이고 간 적 없으면 + dist[nx][ny][1] = nxtdist; + q.push({nx, ny, 1}); + } + + /*아래와 같이하면 broken을 따로 체크안해주니까 여러번 부술 수 있음 */ + // if(arr[nx][ny] == '1' && dist[nx][ny][broken] == -1) { //다음에 갈게 벽이고 간 적없으면 + // dist[nx][ny][1] = nxtdist; + // q.push({nx, ny, 1}); + // } + } + } + return -1; //답을 못찾으면 -1 반환 + +} + +int main() { + + input(); + + cout << bfs(); + + + + return 0; +} \ No newline at end of file