結果

問題 No.297 カードの数式
ユーザー rutilicusrutilicus
提出日時 2020-10-07 21:41:12
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 14,525 ms
コンパイル使用メモリ 427,808 KB
実行使用メモリ 53,416 KB
最終ジャッジ日時 2023-09-27 10:00:52
合計ジャッジ時間 24,349 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 316 ms
52,828 KB
testcase_01 AC 295 ms
52,824 KB
testcase_02 AC 293 ms
53,016 KB
testcase_03 AC 306 ms
53,240 KB
testcase_04 AC 298 ms
53,044 KB
testcase_05 AC 300 ms
52,820 KB
testcase_06 WA -
testcase_07 AC 295 ms
52,920 KB
testcase_08 AC 298 ms
52,852 KB
testcase_09 AC 305 ms
52,872 KB
testcase_10 AC 307 ms
53,196 KB
testcase_11 AC 298 ms
52,916 KB
testcase_12 AC 299 ms
52,960 KB
testcase_13 AC 298 ms
52,924 KB
testcase_14 AC 298 ms
52,928 KB
testcase_15 AC 305 ms
52,804 KB
testcase_16 AC 305 ms
52,992 KB
testcase_17 AC 301 ms
52,964 KB
testcase_18 AC 300 ms
52,916 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 300 ms
52,916 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:60:13: warning: 'appendln(String?): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln("$max $min")
            ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    var plusCnt = 0
    var minusCnt = 0
    val numCnt = IntArray(10)

    readInputLine().split(" ").forEach {
        when(it) {
            "+" -> plusCnt++
            "-" -> minusCnt++
            else -> numCnt[it.toInt()]++
        }
    }

    val digitCnt = n - plusCnt - minusCnt

    val allTermList = mutableListOf<Long>()

    var maxTermTmp = 0L
    var maxTermLen = 0

    for (i in 9 downTo 0) {
        while (numCnt[i] != 0) {
            if (maxTermLen < digitCnt - plusCnt - minusCnt) {
                maxTermTmp = maxTermTmp * 10L + i.toLong()
                maxTermLen++
                if (maxTermLen == digitCnt - plusCnt - minusCnt) {
                    allTermList.add(maxTermTmp)
                }
            } else {
                allTermList.add(i.toLong())
            }
            numCnt[i]--
        }
    }

    allTermList.sortDescending()

    var max = 0L
    for ((i, t) in allTermList.withIndex()) {
        if (i <= plusCnt) {
            max += t
        } else {
            max -= t
        }
    }

    var min = 0L
    for ((i, t) in allTermList.withIndex()) {
        if (i < minusCnt) {
            min -= t
        } else {
            min += t
        }
    }

    builder.appendln("$max $min")

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0