結果

問題 No.297 カードの数式
ユーザー rutilicusrutilicus
提出日時 2020-10-07 21:38:05
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,403 bytes
コンパイル時間 15,476 ms
コンパイル使用メモリ 425,960 KB
実行使用メモリ 55,072 KB
最終ジャッジ日時 2023-09-27 10:00:23
合計ジャッジ時間 24,066 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 270 ms
52,988 KB
testcase_01 AC 267 ms
52,852 KB
testcase_02 AC 265 ms
52,876 KB
testcase_03 AC 273 ms
53,088 KB
testcase_04 WA -
testcase_05 AC 267 ms
54,928 KB
testcase_06 WA -
testcase_07 AC 268 ms
53,072 KB
testcase_08 AC 276 ms
53,304 KB
testcase_09 AC 266 ms
53,016 KB
testcase_10 AC 266 ms
52,988 KB
testcase_11 AC 264 ms
53,016 KB
testcase_12 AC 270 ms
53,000 KB
testcase_13 AC 279 ms
53,036 KB
testcase_14 AC 269 ms
52,980 KB
testcase_15 AC 267 ms
53,080 KB
testcase_16 AC 272 ms
53,228 KB
testcase_17 AC 271 ms
53,040 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 279 ms
53,156 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<Int>()

    var maxTermTmp = 0
    var maxTermLen = 0

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

    allTermList.sortDescending()

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

    var min = 0
    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