結果

問題 No.1373 Directed Operations
ユーザー 👑 箱
提出日時 2021-02-05 21:36:36
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 848 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 14,995 ms
コンパイル使用メモリ 414,536 KB
実行使用メモリ 66,732 KB
最終ジャッジ日時 2023-09-15 07:21:17
合計ジャッジ時間 29,058 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 324 ms
57,048 KB
testcase_01 AC 307 ms
56,352 KB
testcase_02 AC 602 ms
62,728 KB
testcase_03 AC 493 ms
62,000 KB
testcase_04 AC 508 ms
60,776 KB
testcase_05 AC 318 ms
57,264 KB
testcase_06 AC 794 ms
66,472 KB
testcase_07 AC 354 ms
57,332 KB
testcase_08 AC 462 ms
57,912 KB
testcase_09 AC 686 ms
61,348 KB
testcase_10 AC 677 ms
63,228 KB
testcase_11 AC 507 ms
58,676 KB
testcase_12 AC 639 ms
63,380 KB
testcase_13 AC 403 ms
57,480 KB
testcase_14 AC 814 ms
66,520 KB
testcase_15 AC 783 ms
63,920 KB
testcase_16 AC 848 ms
66,732 KB
testcase_17 AC 626 ms
63,872 KB
testcase_18 AC 519 ms
58,016 KB
testcase_19 AC 610 ms
61,288 KB
testcase_20 AC 648 ms
61,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val a = Array(n - 1) { nextInt() }
    val b = (0 until n - 1).map { a[it] to it }.sortedBy { it.first }.toList()
    val op = Array(n - 1) { 0 }
    for (i in 0 until n - 1) {
        if (b[i].first !in 1..1 + i) {
            println("NO")
            return
        }
        op[b[i].second] = i + 2 - b[i].first
    }
    println("YES")
    println(op.joinToString("\n"))
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()!!
fun nextDouble() = next().toDouble()
// endregion
0