結果

問題 No.938 賢人を探せ
ユーザー qszhuqszhu
提出日時 2022-10-05 23:17:06
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 15,778 ms
コンパイル使用メモリ 426,792 KB
実行使用メモリ 59,536 KB
最終ジャッジ日時 2023-08-30 13:03:17
合計ジャッジ時間 28,930 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 509 ms
59,368 KB
testcase_01 AC 306 ms
53,544 KB
testcase_02 AC 307 ms
55,212 KB
testcase_03 AC 305 ms
54,996 KB
testcase_04 AC 305 ms
55,164 KB
testcase_05 AC 298 ms
53,160 KB
testcase_06 AC 306 ms
53,172 KB
testcase_07 AC 302 ms
53,492 KB
testcase_08 AC 466 ms
59,536 KB
testcase_09 AC 471 ms
59,248 KB
testcase_10 AC 296 ms
53,160 KB
testcase_11 AC 460 ms
59,080 KB
testcase_12 AC 464 ms
59,384 KB
testcase_13 AC 462 ms
57,472 KB
testcase_14 AC 466 ms
57,332 KB
testcase_15 AC 493 ms
57,808 KB
testcase_16 AC 469 ms
59,324 KB
testcase_17 AC 473 ms
57,468 KB
testcase_18 AC 468 ms
58,920 KB
testcase_19 AC 467 ms
57,576 KB
testcase_20 AC 472 ms
57,504 KB
testcase_21 AC 472 ms
59,236 KB
testcase_22 AC 502 ms
59,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.system.exitProcess

val br = System.`in`.bufferedReader()

fun readLine(): String? = br.readLine()
fun readString() = readLine()!!
fun readInt() = readString().toInt()
fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf()

const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024

fun main() {
    val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE)
    thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) }
    thread.start()
}

fun run() {
    val N = readInt()
    val pairs = Array(N) { readStrings() }
    output(solve(pairs))
}

fun solve(pairs: Array<List<String>>): List<String> {
    val cheaters = pairs.map { it.first() }.toHashSet()
    val used = HashSet<String>()
    val res = mutableListOf<String>()
    pairs.map { it[1] }.forEach {
        if (it !in cheaters && !used.contains(it)) {
            res.add(it)
            used.add(it)
        }
    }
    return res
}

fun output(res: List<String>) =
    res.joinToString("\n")
        .apply { println(this) }
0