-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from wellFoundedDevelopers/byeonghee/48week
[소병희] 백도어, 탑, 주차장
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package byeonghee.week48 | ||
|
||
import java.util.* | ||
|
||
class 소병희_백도어 { | ||
|
||
companion object { | ||
const val INF = Long.MAX_VALUE | ||
|
||
fun solve()= with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val hideable = readLine().split(" ").map { it == "0" }.toBooleanArray() | ||
val adj = Array(n) { ArrayDeque<Pair<Int, Long>>() } | ||
|
||
repeat(m) { | ||
val (a, b, t) = readLine().split(" ").map { it.toInt() } | ||
adj[a].add(b to t.toLong()) | ||
adj[b].add(a to t.toLong()) | ||
} | ||
|
||
val visited = LongArray(n) { INF } | ||
val q = PriorityQueue<Pair<Int, Long>> { a, b -> (a.second - b.second).toInt() } | ||
val GOAL = n-1 | ||
|
||
visited[0] = 0L | ||
q.add(0 to 0L) | ||
|
||
while(q.isNotEmpty()) { | ||
val (pos, curDist) = q.poll() | ||
|
||
if (visited[pos] < curDist) continue | ||
visited[pos] = curDist | ||
|
||
for((v, e) in adj[pos]) { | ||
if (v != GOAL && hideable[v].not()) continue | ||
if (curDist + e < visited[v]) { | ||
visited[v] = curDist + e | ||
q.add(v to visited[v]) | ||
} | ||
} | ||
} | ||
|
||
println(if (visited[GOAL] == INF) -1 else visited[GOAL]) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_백도어.solve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package byeonghee.week48 | ||
|
||
import java.util.PriorityQueue | ||
import kotlin.collections.ArrayDeque | ||
|
||
class 소병희_주차장 { | ||
|
||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt()} | ||
val fee = IntArray(n) | ||
val weight = IntArray(m + 1) | ||
val parked = IntArray(m + 1) { -1 } | ||
val spaceQ = PriorityQueue<Int>() | ||
val waitQ = ArrayDeque<Int>() | ||
var ans = 0 | ||
|
||
repeat(n) { i -> fee[i] = readLine().toInt() } | ||
repeat(m) { i -> weight[i+1] = readLine().toInt() } | ||
|
||
spaceQ.addAll(0 until n) | ||
repeat(2*m) { | ||
val car = readLine().toInt() | ||
|
||
if (car < 0) { | ||
val space = parked[car * -1] | ||
parked[car * -1] = -1 | ||
spaceQ.add(space) | ||
ans += fee[space] * weight[car * -1] | ||
} | ||
else waitQ.add(car) | ||
|
||
if (spaceQ.isNotEmpty() && waitQ.isNotEmpty()) { | ||
val space = spaceQ.poll() | ||
val car = waitQ.removeFirst() | ||
|
||
parked[car] = space | ||
} | ||
} | ||
|
||
println(ans) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package byeonghee.week48 | ||
|
||
class 소병희_탑 { | ||
|
||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val n = readLine().toInt() | ||
val towers = IntArray(n) | ||
val st = ArrayDeque<Int>() | ||
val answer = IntArray(n) | ||
|
||
|
||
readLine().split(" ").forEachIndexed { i, v -> | ||
towers[i] = v.toInt() | ||
} | ||
|
||
for(reach in n-1 downTo 0) { | ||
while (st.isNotEmpty() && towers[reach] > towers[st.first()]) { | ||
answer[st.removeFirst()] = reach + 1 | ||
} | ||
|
||
st.addFirst(reach) | ||
} | ||
|
||
println(answer.joinToString(" ")) | ||
} | ||
} | ||
} |