結果

問題 No.944 煎っぞ!
ユーザー qszhuqszhu
提出日時 2022-10-07 19:59:47
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 480 ms / 3,000 ms
コード長 1,194 bytes
コンパイル時間 14,430 ms
コンパイル使用メモリ 420,940 KB
実行使用メモリ 60,412 KB
最終ジャッジ日時 2023-09-02 21:20:25
合計ジャッジ時間 31,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 464 ms
60,112 KB
testcase_01 AC 466 ms
58,084 KB
testcase_02 AC 468 ms
60,164 KB
testcase_03 AC 468 ms
58,004 KB
testcase_04 AC 468 ms
59,928 KB
testcase_05 AC 461 ms
57,980 KB
testcase_06 AC 471 ms
58,068 KB
testcase_07 AC 474 ms
58,436 KB
testcase_08 AC 478 ms
58,416 KB
testcase_09 AC 474 ms
59,916 KB
testcase_10 AC 343 ms
59,444 KB
testcase_11 AC 391 ms
59,464 KB
testcase_12 AC 361 ms
59,360 KB
testcase_13 AC 309 ms
57,240 KB
testcase_14 AC 367 ms
57,964 KB
testcase_15 AC 353 ms
59,352 KB
testcase_16 AC 309 ms
57,328 KB
testcase_17 AC 310 ms
59,124 KB
testcase_18 AC 374 ms
59,440 KB
testcase_19 AC 373 ms
59,408 KB
testcase_20 AC 465 ms
58,088 KB
testcase_21 AC 463 ms
59,912 KB
testcase_22 AC 465 ms
60,012 KB
testcase_23 AC 465 ms
58,080 KB
testcase_24 AC 468 ms
59,880 KB
testcase_25 AC 471 ms
58,092 KB
testcase_26 AC 472 ms
58,340 KB
testcase_27 AC 465 ms
60,308 KB
testcase_28 AC 309 ms
57,252 KB
testcase_29 AC 311 ms
59,228 KB
testcase_30 AC 473 ms
59,992 KB
testcase_31 AC 476 ms
60,412 KB
testcase_32 AC 475 ms
59,912 KB
testcase_33 AC 480 ms
59,988 KB
testcase_34 AC 473 ms
58,436 KB
権限があれば一括ダウンロードができます

ソースコード

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() {
    readInt()
    val a = readInts()
    output(solve(a))
}

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

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

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

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