結果

問題 No.944 煎っぞ!
ユーザー qszhu
提出日時 2022-10-07 19:56:28
言語 Kotlin
(2.1.0)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 17,302 ms
コンパイル使用メモリ 446,376 KB
実行使用メモリ 65,532 KB
最終ジャッジ日時 2024-06-12 03:33:20
合計ジャッジ時間 31,768 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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