結果
| 問題 |
No.938 賢人を探せ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-05 23:17:06 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 523 ms / 2,000 ms |
| コード長 | 1,050 bytes |
| コンパイル時間 | 15,043 ms |
| コンパイル使用メモリ | 480,264 KB |
| 実行使用メモリ | 71,836 KB |
| 最終ジャッジ日時 | 2025-01-02 02:36:23 |
| 合計ジャッジ時間 | 25,036 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
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) }