結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-09-28 06:51:12 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 891 ms / 5,000 ms |
| コード長 | 1,618 bytes |
| コンパイル時間 | 16,669 ms |
| コンパイル使用メモリ | 457,140 KB |
| 実行使用メモリ | 96,264 KB |
| 最終ジャッジ日時 | 2024-10-01 06:57:25 |
| 合計ジャッジ時間 | 28,361 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
^
Main.kt:5:9: warning: variable 'cityCount' is never used
val(cityCount, roadCount, logCount) = readLine()!!.split(" ").map { it.toInt() }
^
Main.kt:5:31: warning: variable 'logCount' is never used
val(cityCount, roadCount, logCount) = readLine()!!.split(" ").map { it.toInt() }
^
ソースコード
import kotlin.math.PI
fun main(arr:Array<String>) {
val(cityCount, roadCount, logCount) = readLine()!!.split(" ").map { it.toInt() }
val roads = mutableMapOf<Int,MutableMap<Int, MutableMap<Long, Boolean>>>()
(0 until roadCount).forEach {
val(city1, city2, cost) = readLine()!!.split(" ").map { it.toInt() }
if(!roads.containsKey(city1)) {
roads[city1] = mutableMapOf()
}
if(!roads.containsKey(city2)) {
roads[city2] = mutableMapOf()
}
if(!roads[city1]!!.containsKey(city2)) {
roads[city1]!![city2] = mutableMapOf()
}
if(!roads[city2]!!.containsKey(city1)) {
roads[city2]!![city1] = mutableMapOf()
}
roads[city1]!![city2]!![cost.toLong()] = true
roads[city2]!![city1]!![cost.toLong()] = true
}
val log = readLine()!!.split(" ").map { it.toLong() }
val ans = Proc(roads, log).getAns()
println(ans.size)
println(ans.sorted().joinToString(" "))
}
class Proc(val roads:Map<Int, Map<Int,Map<Long, Boolean>>>, val log:List<Long>) {
public fun getAns():List<Int> {
var currentList = roads.map { a->a.value.filter { b-> log[0] in b.value.keys }.map { it.key }.toMutableList() }.reduce { acc, list -> acc.union(list).toMutableList() }.toList()
for(i in log.drop(1)) {
currentList = currentList.map { a->roads[a]?.let { b-> b.filter { i in it.value.keys }.keys.toMutableList() }?: mutableListOf() }.reduce { acc, mutableList -> acc.union(mutableList).toMutableList() }.toList()
}
return currentList
}
}
バカらっく