結果

問題 No.1373 Directed Operations
ユーザー face4face4
提出日時 2021-07-24 11:31:44
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 874 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 15,650 ms
コンパイル使用メモリ 415,300 KB
実行使用メモリ 71,604 KB
最終ジャッジ日時 2023-09-26 22:06:42
合計ジャッジ時間 31,496 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
57,036 KB
testcase_01 AC 303 ms
57,108 KB
testcase_02 AC 628 ms
65,704 KB
testcase_03 AC 493 ms
61,720 KB
testcase_04 AC 520 ms
71,604 KB
testcase_05 AC 285 ms
53,036 KB
testcase_06 AC 820 ms
66,968 KB
testcase_07 AC 363 ms
57,464 KB
testcase_08 AC 465 ms
57,620 KB
testcase_09 AC 740 ms
66,668 KB
testcase_10 AC 692 ms
62,224 KB
testcase_11 AC 534 ms
60,344 KB
testcase_12 AC 650 ms
62,600 KB
testcase_13 AC 416 ms
57,624 KB
testcase_14 AC 874 ms
69,208 KB
testcase_15 AC 844 ms
67,348 KB
testcase_16 AC 874 ms
69,108 KB
testcase_17 AC 665 ms
64,268 KB
testcase_18 AC 540 ms
57,916 KB
testcase_19 AC 626 ms
59,980 KB
testcase_20 AC 706 ms
66,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*
import kotlin.system.exitProcess

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    val ord = a.zip(0 until n - 1).sortedBy { it.first }
    var ans = MutableList(n - 1) { 0 }
    var pos = 0
    val queue = LinkedList<Pair<Int, Int>>()
    for (i in 2..n) {
        while (pos < n - 1 && ord[pos].first == i - 1) queue.add(ord[pos++])
        if (queue.isEmpty()) {
            println("NO")
            exitProcess(0)
        }
        val (value, index) = queue.poll()!!
        ans[index] = i - value
    }
    println("YES")
    println(ans.joinToString("\n"))
}
0