BOJ: #2468 - ์์ ์์ญ
๋ค์ด์ฌ ์ ์๋ ๋์ด๋ 1~100 ์ฌ์ด์ด๊ธฐ ๋๋ฌธ์, ์ฅ๋ง์ฒ ์ ๋ฌผ์ด ์์ผ ์ ์๋ ๋์ด๋ 1~100 ์ฌ์ด๋ค. ๊ทธ๋์ ๋ฐ๋ณตํ๋ฉด์ ์์ ์์ญ์ ๊ฐ์๋ฅผ ์ฒดํฌํด์ฃผ๋ฉด ๋๋๋ฐ, ์ด ๋ ์๋ฌด ์ง์ญ๋ ์ ๊ธฐ์ง ์์ ์ ์์ด์ ๋ฐ๋ณต๋ฌธ์ 0๋ถํฐ ์์ํ๊ฒ ํด ์คฌ๋ค. ์ด ์์ด๋์ด์ ๋ํ ๋ถ๋ถ์ ์ด ๊ธ์ ๋๊ธ์ ์ฐธ๊ณ ํ๋ค.
๋ฌธ์
https://www.acmicpc.net/problem/2468
๋ด๊ฐ ์์ฑํ ์ฝ๋
Swift
let dx = [1, 0, -1, 0]
let dy = [0, 1, 0, -1]
let n = Int(readLine()!)!
var board = [[Int]]()
for _ in 0..<n {
let area = readLine()!.split(separator: " ").map { Int(String($0))! }
board.append(area)
}
var max = 0
for i in 0...100 {
var graph = board
// ์ ๊ธฐ๋ ์ง์ญ ์ฒดํฌ
for j in 0..<n {
for k in 0..<n {
if graph[j][k] <= i {
graph[j][k] = 0
}
}
}
// ์ง์ญ ๊ฐ์ ์ฒดํฌ
var count = 0
for j in 0..<n {
for k in 0..<n {
if graph[j][k] != 0 {
var visited = [[j, k]]
var queue = [[j, k]]
while !queue.isEmpty {
let v = queue.removeFirst()
for (x, y) in zip(dx, dy) {
let nx = v[0] + x
let ny = v[1] + y
if nx < 0 || nx >= n || ny < 0 || ny >= n || graph[nx][ny] == 0 {
continue
}
if graph[nx][ny] != 0 {
visited.append([nx, ny])
queue.append([nx, ny])
graph[nx][ny] = 0
}
}
}
count += 1
}
}
}
max = count > max ? count : max
}
print(max)
๋ฐ์ํ
๋๊ธ
์ด ๊ธ ๊ณต์ ํ๊ธฐ
-
๊ตฌ๋
ํ๊ธฐ
๊ตฌ๋ ํ๊ธฐ
-
์นด์นด์คํก
์นด์นด์คํก
-
๋ผ์ธ
๋ผ์ธ
-
ํธ์ํฐ
ํธ์ํฐ
-
Facebook
Facebook
-
์นด์นด์ค์คํ ๋ฆฌ
์นด์นด์ค์คํ ๋ฆฌ
-
๋ฐด๋
๋ฐด๋
-
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
-
Pocket
Pocket
-
Evernote
Evernote