結果

問題 No.1279 Array Battle
ユーザー 👑 箱
提出日時 2020-11-06 21:23:20
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 648 ms / 2,000 ms
コード長 1,892 bytes
コンパイル時間 17,227 ms
コンパイル使用メモリ 431,528 KB
実行使用メモリ 62,744 KB
最終ジャッジ日時 2023-09-29 18:02:23
合計ジャッジ時間 25,214 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 261 ms
52,932 KB
testcase_01 AC 276 ms
56,064 KB
testcase_02 AC 281 ms
56,120 KB
testcase_03 AC 258 ms
52,812 KB
testcase_04 AC 269 ms
52,712 KB
testcase_05 AC 268 ms
53,076 KB
testcase_06 AC 275 ms
56,184 KB
testcase_07 AC 274 ms
56,268 KB
testcase_08 AC 265 ms
53,216 KB
testcase_09 AC 282 ms
56,040 KB
testcase_10 AC 293 ms
56,320 KB
testcase_11 AC 292 ms
56,572 KB
testcase_12 AC 399 ms
61,136 KB
testcase_13 AC 493 ms
62,480 KB
testcase_14 AC 513 ms
62,744 KB
testcase_15 AC 613 ms
62,628 KB
testcase_16 AC 617 ms
62,528 KB
testcase_17 AC 641 ms
62,616 KB
testcase_18 AC 623 ms
62,512 KB
testcase_19 AC 648 ms
62,648 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:44:29: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int
    val max = map.keys.max()!!
                            ^

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList

fun nextPermutation(array: MutableList<Int>): Boolean {
    var tmp: Int
    for (i in array.size - 2 downTo 0) {
        if (array[i] < array[i + 1]) {
            for (j in array.size - 1 downTo i + 1) {
                if (array[j] > array[i]) {
                    tmp = array[i]
                    array[i] = array[j]
                    array[j] = tmp

                    val tmpArray = array.takeLast(array.size - (i + 1)).sorted()
                    tmpArray.forEachIndexed { index, e ->
                        array[i + 1 + index] = e
                    }

                    return true
                }
            }
        }
    }
    return false
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val b = Array(n) { sc.nextInt() }
    val p = (0 until n).toMutableList()
    val map = mutableMapOf<Int, Int>()
    do {
        var point = 0
        for (i in 0 until n) {
            point += maxOf(0, a[p[i]] - b[i])
        }
        map[point] = (map[point] ?: 0) + 1
    } while (nextPermutation(p))
    val max = map.keys.max()!!
    println(map[max]!!)
}

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

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    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()
    fun ready() = br.ready()
}
0