結果

問題 No.10 +か×か
コンテスト
ユーザー はまやんはまやん
提出日時 2017-06-09 17:00:32
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
AC  
実行時間 1,108 ms / 5,000 ms
コード長 3,027 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,189 ms
コンパイル使用メモリ 489,920 KB
実行使用メモリ 349,644 KB
最終ジャッジ日時 2026-05-14 11:31:27
合計ジャッジ時間 18,159 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:72:9: warning: identity equality for arguments of types 'Int' and 'Int' is deprecated.
    if (lenbuf === -1) throw InputMismatchException()
        ^^^^^^^^^^^^^
Main.kt:95:21: warning: 'fun toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if(b >= '0'.toByte() && b <= '9'.toByte() || b == '-'.toByte()) break
                    ^^^^^^
Main.kt:95:42: warning: 'fun toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if(b >= '0'.toByte() && b <= '9'.toByte() || b == '-'.toByte()) break
                                         ^^^^^^
Main.kt:95:63: warning: 'fun toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if(b >= '0'.toByte() && b <= '9'.toByte() || b == '-'.toByte()) break
                                                              ^^^^^^
Main.kt:97:22: warning: 'fun toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if (b == '-'.toByte()) {
                     ^^^^^^
Main.kt:104:22: warning: 'fun toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if (b >= '0'.toByte() && b <= '9'.toByte()) {
                     ^^^^^^
Main.kt:104:43: warning: 'fun toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        if (b >= '0'.toByte() && b <= '9'.toByte()) {
                                          ^^^^^^
Main.kt:105:39: warning: 'fun toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
            num = num * 10 + (b - '0'.toByte())
                                      ^^^^^^

ソースコード

diff #
raw source code

import java.io.*
import java.util.InputMismatchException
import java.io.IOException
import javax.swing.text.MutableAttributeSet
import kotlin.system.measureTimeMillis
var out = PrintWriter(System.out)
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/


fun solve() {
    var N = ni()
    var TOTAL = ni()
    var A = na(N)

    var dp = Array(N + 1, { Array(101010, {0}).toMutableList() })
    var pre = Array<MutableList<String>>(N + 1, { Array(101010, {""}).toMutableList() })

    dp[0][A[0]] = 1

    for(i in 0 until N - 1)  for(j in 0..100000) if(0 < dp[i][j]) {
        var x = A[i + 1]
        // +
        if(j + x < 101010) {
            dp[i + 1][j + x] = 1
            if(pre[i + 1][j + x].length == 0) pre[i + 1][j + x] = pre[i][j] + "+"
            else if(pre[i][j] + "+" > pre[i + 1][j + x]) pre[i + 1][j + x] = pre[i][j] + "+"
        }

        // *
        if(j.toLong() * x.toLong() < 101010L) {
            dp[i + 1][j * x] = 1
            if(pre[i + 1][j * x].length == 0) pre[i + 1][j * x] = pre[i][j] + "*"
            else if(pre[i][j] + "*" > pre[i + 1][j * x]) pre[i + 1][j * x] = pre[i][j] + "*"
        }
    }

    out.println(pre[N - 1][TOTAL])
}









//---------------------------------------------------------------------------------------------------
fun main(args: Array<String>) {
    var time = measureTimeMillis {
        solve()
        out.flush()
    }
    //println("$time ms")
}
//---------------------------------------------------------------------------------------------------
private var inbuf = ByteArray(1024)
private var lenbuf = 0
var ptrbuf = 0

var `is` = System.`in`

fun readByte(): Byte {
    if (lenbuf === -1) throw InputMismatchException()
    if (ptrbuf >= lenbuf) {
        ptrbuf = 0
        try {
            lenbuf = `is`.read(inbuf)
        } catch (e: IOException) {
            throw InputMismatchException()
        }

        if (lenbuf <= 0) return -1
    }
    return inbuf[ptrbuf++]
}

fun na(n: Int) = IntArray(n, {ni()})

fun ni(): Int {
    var num = 0
    var b: Byte
    var minus = false
    while (true) {
        b = readByte()
        if(b < 0) break
        if(b >= '0'.toByte() && b <= '9'.toByte() || b == '-'.toByte()) break

        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
    }

    while (true) {
        if (b >= '0'.toByte() && b <= '9'.toByte()) {
            num = num * 10 + (b - '0'.toByte())
        } else {
            return if (minus) -num else num
        }
        b = readByte()
    }
}
0