結果

問題 No.944 煎っぞ!
ユーザー qszhuqszhu
提出日時 2022-10-07 19:27:05
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 15,239 ms
コンパイル使用メモリ 428,536 KB
実行使用メモリ 61,836 KB
最終ジャッジ日時 2023-09-02 20:33:21
合計ジャッジ時間 32,863 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 469 ms
59,856 KB
testcase_01 AC 464 ms
58,192 KB
testcase_02 AC 465 ms
59,736 KB
testcase_03 AC 470 ms
57,856 KB
testcase_04 AC 473 ms
59,756 KB
testcase_05 AC 461 ms
57,828 KB
testcase_06 AC 462 ms
59,816 KB
testcase_07 AC 466 ms
59,784 KB
testcase_08 AC 479 ms
57,888 KB
testcase_09 AC 471 ms
57,816 KB
testcase_10 AC 341 ms
57,188 KB
testcase_11 AC 394 ms
59,180 KB
testcase_12 AC 379 ms
59,084 KB
testcase_13 AC 333 ms
59,072 KB
testcase_14 AC 394 ms
57,664 KB
testcase_15 AC 376 ms
59,928 KB
testcase_16 WA -
testcase_17 AC 324 ms
58,972 KB
testcase_18 AC 385 ms
59,128 KB
testcase_19 AC 384 ms
59,448 KB
testcase_20 AC 467 ms
58,484 KB
testcase_21 AC 462 ms
59,620 KB
testcase_22 AC 496 ms
59,536 KB
testcase_23 AC 480 ms
59,512 KB
testcase_24 AC 485 ms
57,832 KB
testcase_25 AC 473 ms
57,888 KB
testcase_26 AC 470 ms
57,892 KB
testcase_27 AC 484 ms
59,584 KB
testcase_28 AC 328 ms
57,508 KB
testcase_29 AC 323 ms
57,416 KB
testcase_30 AC 486 ms
59,752 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:25:11: warning: parameter 'N' is never used
fun solve(N: Int, a: IntArray): Int {
          ^
Main.kt:29:13: warning: name shadowed: sum
        var sum = 0
            ^

ソースコード

diff #

import kotlin.system.exitProcess

val br = System.`in`.bufferedReader()

fun readLine(): String? = br.readLine()
fun readString() = readLine()!!
fun readInt() = readString().toInt()
fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf()
fun readInts() = readStrings().map { it.toInt() }.toIntArray()

const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024

fun main() {
    val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE)
    thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) }
    thread.start()
}

fun run() {
    val N = readInt()
    val a = readInts()
    output(solve(N, a))
}

fun solve(N: Int, a: IntArray): Int {
    val sum = a.sum()

    fun canDivide(target: Int): Boolean {
        var sum = 0
        for (ai in a) {
            sum += ai
            if (sum == target) sum = 0
            else if (sum > target) return false
        }
        return sum == 0
    }

    var res = 1
    var i = 2
    while (i * i <= sum) {
        if (sum % i == 0) {
            val target = sum / i
            if (canDivide(target)) res = i
        }
        i++
    }
    return res
}

fun output(res: Int) = println(res)
0