Skip to content

Commit 3192630

Browse files
committed
add all files
1 parent 63ba8eb commit 3192630

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+166
-0
lines changed

Diff for: .idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/BOJ-Java.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/kotlinc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/libraries/KotlinJavaRuntime.xml

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: baekjoon/src/kotlinsource/B_14502.kt

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package baekjoon.src.kotlinsource
2+
3+
import java.util.*
4+
5+
fun main() = with(System.`in`.bufferedReader()) {
6+
val n: Int
7+
val m: Int
8+
9+
readLine().split(" ").run {
10+
n = this[0].toInt()
11+
m = this[1].toInt()
12+
}
13+
14+
val arr = Array(n) { IntArray(m) }
15+
val viruses = mutableListOf<IntArray>()
16+
17+
for (i in 0 until n) {
18+
val st = StringTokenizer(readLine())
19+
for (j in 0 until m) {
20+
arr[i][j] = st.nextToken().toInt()
21+
if (arr[i][j] == 2) {
22+
viruses.add(intArrayOf(i, j))
23+
}
24+
}
25+
}
26+
27+
var answer = 0
28+
29+
fun check(x: Int, y: Int) = x < 0 || x >= n || y < 0 || y >= m
30+
31+
fun calculateArea(visit: Array<BooleanArray>): Int {
32+
var area = 0
33+
34+
for (i in 0 until n) {
35+
for (j in 0 until m) {
36+
if (arr[i][j] == 0 && !visit[i][j]) area++
37+
}
38+
}
39+
40+
return area
41+
}
42+
43+
fun bfs() {
44+
val dx = intArrayOf(-1, 1, 0, 0)
45+
val dy = intArrayOf(0, 0, -1, 1)
46+
47+
val visit = Array(n) { BooleanArray(m) }
48+
val q = LinkedList<IntArray>()
49+
50+
q.addAll(viruses)
51+
52+
while (!q.isEmpty()) {
53+
val now = q.poll()
54+
55+
for (i in 0..3) {
56+
val nextX = now[0] + dx[i]
57+
val nextY = now[1] + dy[i]
58+
59+
if (check(nextX, nextY) || arr[nextX][nextY] != 0 || visit[nextX][nextY]) {
60+
continue
61+
}
62+
63+
visit[nextX][nextY] = true
64+
q.offer(intArrayOf(nextX, nextY))
65+
}
66+
}
67+
68+
val area = calculateArea(visit)
69+
answer = if (answer < area) area else answer
70+
}
71+
72+
fun dfs(startIdx: Int, depth: Int, size: Int) {
73+
if (depth == size) {
74+
bfs()
75+
return
76+
}
77+
78+
if (startIdx >= n * m) return
79+
80+
for (idx in startIdx until n * m) {
81+
val i = idx / m
82+
val j = idx % m
83+
84+
if (arr[i][j] != 0) continue
85+
86+
arr[i][j] = 1
87+
dfs(idx + 1, depth + 1, size)
88+
arr[i][j] = 0
89+
}
90+
}
91+
92+
dfs(0, 0, 3)
93+
print(answer)
94+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)