結果

問題 No.944 煎っぞ!
ユーザー qszhuqszhu
提出日時 2022-10-07 19:56:28
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 17,882 ms
コンパイル使用メモリ 426,648 KB
実行使用メモリ 60,052 KB
最終ジャッジ日時 2023-09-02 21:15:16
合計ジャッジ時間 34,629 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 479 ms
59,720 KB
testcase_01 AC 482 ms
57,800 KB
testcase_02 AC 474 ms
57,920 KB
testcase_03 AC 475 ms
57,788 KB
testcase_04 AC 474 ms
59,676 KB
testcase_05 AC 474 ms
57,944 KB
testcase_06 AC 477 ms
58,296 KB
testcase_07 AC 471 ms
57,880 KB
testcase_08 AC 472 ms
57,960 KB
testcase_09 AC 482 ms
58,124 KB
testcase_10 AC 330 ms
56,976 KB
testcase_11 AC 389 ms
59,204 KB
testcase_12 AC 375 ms
57,264 KB
testcase_13 AC 327 ms
57,228 KB
testcase_14 AC 394 ms
59,192 KB
testcase_15 AC 373 ms
59,264 KB
testcase_16 AC 325 ms
59,072 KB
testcase_17 AC 329 ms
59,072 KB
testcase_18 AC 382 ms
59,320 KB
testcase_19 AC 384 ms
59,132 KB
testcase_20 AC 460 ms
59,668 KB
testcase_21 AC 463 ms
58,116 KB
testcase_22 AC 466 ms
57,948 KB
testcase_23 AC 476 ms
59,664 KB
testcase_24 AC 471 ms
59,728 KB
testcase_25 AC 469 ms
60,052 KB
testcase_26 AC 487 ms
57,792 KB
testcase_27 AC 471 ms
59,736 KB
testcase_28 AC 322 ms
58,980 KB
testcase_29 AC 327 ms
58,984 KB
testcase_30 AC 479 ms
57,944 KB
testcase_31 WA -
testcase_32 AC 482 ms
59,904 KB
testcase_33 AC 497 ms
59,876 KB
testcase_34 AC 483 ms
59,660 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 = 1
    var i = 2
    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