Skip to content

[Algorithm] 봄버맨 #175

Description

@hwangJi-dev

💬 문제

https://www.acmicpc.net/problem/16918


💬 Idea

  • N이 짝수면 모두 O인(모두 폭탄인) 배열을 문자열로 출력하고,
  • N이 홀수이면 반복문을 2 간격으로 돌면서 폭탄 배열을 갱신한다.
    • 가장 처음에 봄버맨은 일부 칸에 폭탄을 설치해 놓는다. 모든 폭탄이 설치된 시간은 같다.(1)
    • 다음 1초 동안 봄버맨은 아무것도 하지 않는다.(1)
    • 다음 1초 동안 폭탄이 설치되어 있지 않은 모든 칸에 폭탄을 설치한다. 즉, 모든 칸은 폭탄을 가지고 있게 된다. 폭탄은 모두 동시에 설치했다고 가정한다. (2)
    • 1초가 지난 후에 3초 전에 설치된 폭탄이 모두 폭발한다. (3)
    • 3과 4를 반복한다. (—> 간격 2씩 폭탄 배열의 O 터뜨리고 터진 곳 . 으로 갱신)

💬 풀이

import Foundation
func solution16918(){letRCN=readLine()!.split(separator:"").map({Int(String($0))! })varbombArr:[[String]]=[]for_in0..<RCN[0]{
bombArr.append(Array(readLine()!).map({String($0)}))}varallBombArr:[[String]]=[]func bomb(x:Int, y:Int){allBombArr[x][y]="."if x +1<= bombArr.count -1{allBombArr[x +1][y]="."}if x -1>=0{allBombArr[x -1][y]="."}if y +1<=bombArr[0].count -1{allBombArr[x][y +1]="."}if y -1>=0{allBombArr[x][y -1]="."}}for_instride(from:1, to:RCN[2], by:2){
allBombArr =Array(repeating:Array(repeating:"O", count:bombArr[0].count), count: bombArr.count)for(idx, i)in bombArr.enumerated(){for(jdx, _)in i.enumerated(){ifbombArr[idx][jdx]=="O"{bomb(x: idx, y: jdx)}}}
bombArr = allBombArr
}ifRCN[2]%2==0{for_in bombArr {print(String(repeating:"O", count:bombArr[0].count))}}else{foriin bombArr {print(i.joined())}}}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions