結果
| 問題 |
No.944 煎っぞ!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-07 19:21:29 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,189 bytes |
| コンパイル時間 | 16,801 ms |
| コンパイル使用メモリ | 457,764 KB |
| 実行使用メモリ | 64,156 KB |
| 最終ジャッジ日時 | 2024-06-12 02:45:26 |
| 合計ジャッジ時間 | 35,845 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 5 |
ソースコード
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 preSum = a.scan(0, Int::plus)
fun canDivide(target: Int): Boolean {
var i = 0
for (j in 1..N) {
val sum = preSum[j] - preSum[i]
if (sum == target) i = j
else if (sum > target) return false
}
return true
}
var res = 1
var i = 2
while (i * i <= preSum.last()) {
val sum = preSum.last() / i
if (canDivide(sum)) res = i
i++
}
return res
}
fun output(res: Int) = println(res)